Details
-
Type:
Improvement
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: None
-
Fix Version/s: X10 2.3.2
-
Component/s: X10 Compiler: Front-end Typechecking
-
Labels:None
-
Number of attachments :
Description
When I compile:
public class gorb { public static def main(argv:Array[String](1)) { val b : Array[Int] = [3 as Int, 3]; b(2) = 1; } }
I get the error message:
x10c -STATIC_CHECKS gorb.x10
/Users/bard/x10/tmp/gorb.x10:4: Cannot assign expression to array element of given type.
Expression: 1
Type: x10.lang.Int{self==1}
Array element: b(2)
Type: x10.lang.Int
Cause: Call invalid; calling environment does not entail the method guard.
arg types:[x10.lang.Int{self==2}, x10.lang.Int{self==1}]
query residue: {b.rank==1}
1 error.
~/x10/tmp:
Which confused me greatly. The message talks about an 'expression' and an
'array element', so I looked at the things labelled 'expression' and 'array
element', which made me think that I couldn't assign an Int{self==1} to
an array of Int somehow.
Actually, the problem somewhat explained by the 'Cause', and more by the
'query residue', which, translated to English, say that b is not known to
be a one-dimensional array so we can't necessarily make the call b(1).
('query residue' is a fine technical term, but not a very good explanation for
most users.)
This error message, while it does have all the information, is sufficiently
perplexing so that I couldn't figure it out at first or even at third reading.
Here's a way to rephrase it which might be more helpful. It's pretty much the
same information (except that I want to show the whole guard as well as the
residue, and maybe the method signature too), but the cause and important info
comes first, the 'query residue' has been renamed, and the important stuff has
been separated from other helpful details.
Oh, and giving the calling environment would probably be good too, but I don't
know exactly what that is (and if it's too big, it wouldn't be helpful).
x10c -STATIC_CHECKS gorb.x10
/Users/bard/x10/tmp/gorb.x10:4: Ill-typed array assignment operation
Cause: Call invalid; calling environment does not entail the method guard.
Method Guard: {b.rank==1}
What is missing: {b.rank==1}
Method: Array[T] { operator this(i0:int){rank==1}:T }
Other Facts About The Operation:
Expression: 1
Type: x10.lang.Int{self==1}
Array element: b(2)
Type: x10.lang.Int
arg types:[x10.lang.Int{self==2}, x10.lang.Int{self==1}]
1 error.
~/x10/tmp:
BTW, now that I know better what's going on, having the query residue there is very helpful. It will help a lot to make sense out of some errors that had been painful and complicated.