X10
  1. X10
  2. XTENLANG-2549

Compiler emitting a warning for unsound casts

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: X10 2.1.2
    • Fix Version/s: X10 2.2
    • Labels:
      None
    • Number of attachments :
      0

      Description

      In X10 2.3 we intend to do constraint solving at runtime, therefore you could cast:

      x as Array[Int{self!=0}]
      

      by checking the runtime type of x, making sure it's a subtype of Array, and the corresponding generic parameter is equal to
      Int

      {self!=0}

      However, currently in X10 2.2, the runtime erases all constraints at runtime, so casts of the previous form or even these:

      x as Array[Int]
      

      are not sound because:

      public class Hello {
          public static def main(args: Array[String]) {
              val arr = new Array[Int{self==3}](0..100, ([p]:Point(1))=>3);
              //arr(0) = 1; // err: Cannot assign expression to array element of given type.             Expression: 1             Type: x10.lang.Int{self==1}             Array element: arr(0)             Type: x10.lang.Int{self==3}   
              arr(0) = 3;
              val arrAlias = (arr as Any) as Array[Int]; // it should have failed HERE by noting that the RTT is  Array[Int{SOMETHING_THAT_WAS_ERASED}]
              arrAlias(0) = 1;
              val x:Int{self==3} = arr(0); // Broke type safety
              assert x==3 : "We should have failed before"; // but it fails HERE
          }
      }
      

      Therefore the compiler now emits an "Unsound cast" warning on such casts.
      These casts are suppressed in XRX because we do not wish the user to receive these warnings, e.g., whenever he uses HashMap.

      This warning will be removed when the runtime will store constraints and have constraint solving.

        Activity

        Hide
        Yoav Zibin added a comment -

        Fixed in revision 20651.

        I'm suppressing such warnings in XRX classes (Array, FinishState, Runtime, HashMap and HashSet),
        and in compiler generated code (such as equals for structs).

        Show
        Yoav Zibin added a comment - Fixed in revision 20651. I'm suppressing such warnings in XRX classes (Array, FinishState, Runtime, HashMap and HashSet), and in compiler generated code (such as equals for structs).
        Hide
        David Grove added a comment -

        bulk close of all 2.2.0 resolved issues.

        Show
        David Grove added a comment - bulk close of all 2.2.0 resolved issues.

          People

          • Assignee:
            Yoav Zibin
            Reporter:
            Yoav Zibin
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: