Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: X10 2.1.2
-
Fix Version/s: X10 2.2
-
Component/s: X10 Compiler: Front-end
-
Labels:None
-
Number of attachments :
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
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.
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).