Method Resolution doesn't handle user-defined implicit coercions correctly.

Description

Here's what Vijay wrote about method resolution:

1. List all the exact methods that could possibly be used (generic type
inferencing performed; implicit coercions not performed; if DYNAMIC_CHECKS
is on, then constraints need not match exactly)

2. Determine the most specific ones.

3. If there is one; this is the method, stop.

4. If there are more than one, declare an ambiguity error and stop.
5. Repeat steps 1-4, this time with implicit coercions performed.
6. If method is not found, declare no method found and stop.

That doesn't seem to be what X10 is doing.

There are implicit coercions from Byte to Int and Ace, so, by the above rules, this ought to be a static error. Instead, it's not; X10 silently picks the Byte->Int coercion:

x10c Res2.x10
~/x10/tmp: x10 Res2
Int x=100 type=x10.lang.Int
Surface x=Res2.Ace@32bf7190 type=Res2.Ace
Int x=1 type=x10.lang.Int
x10.lang.AssertionError: Byte
at Res2.example(Res2.java:130)
at Res2.main(Res2.java:154)
at Res2$$Main.runtimeCallback(Res2.java:144)
at x10.runtime.impl.java.Runtime$$Closure$Main.$apply(Runtime.java:92)
at x10.lang.Runtime$$Closure$146.$apply(Runtime.java:3966)
at x10.lang.Activity.run(Activity.java:590)
at x10.lang.Runtime$Worker.loop(Runtime.java:1087)
at x10.lang.Runtime$Worker.$apply(Runtime.java:1022)
at x10.lang.Runtime$Pool.$apply(Runtime.java:1540)
at x10.lang.Runtime.start(Runtime.java:2237)
at x10.runtime.impl.java.Runtime.$apply(Runtime.java:132)
at x10.runtime.impl.java.Thread.run(Thread.java:48)
~/x10/tmp:

Here's a similar program, differing only in that the method m looks for an instance of class Ace rather than interface Surface:

This doesn't compile, but the error message doesn't seem to indicate that it's failing to compile for the right reason:

x10c Res3.x10
/Users/bard/x10/tmp/Res3.x10:13: Method m(x: x10.lang.Int): x10.lang.Int{self==1} in Res3{self==Res3#this} cannot be called with arguments (x10.lang.Byte{self==1}); Invalid Parameter.
Expected type: x10.lang.Int
Found type: x10.lang.Byte{self==1}
1 error.
~/x10/tmp:

Environment

None

Status

Assignee

Unassigned

Reporter

Imported User 59

Labels

None

Components

Fix versions

Affects versions

Priority

High
Configure