eclipse-archived / ceylon

The Ceylon compiler, language module, and command line tools
http://ceylon-lang.org
Apache License 2.0
395 stars 62 forks source link

Illegal contravariant refinement allowed on the JVM #7394

Closed jvasileff closed 5 years ago

jvasileff commented 5 years ago

The following is allowed by the type checker, despite #4093 disallowing very similar code:

shared void run() {
    B().echo("" of Object);
    // error: Ceylon backend error: no suitable method found for echo(TypeDescriptor,String)
}

class A() {
    shared default T echo<T>(T t) given T satisfies String => t;
}

class B() extends A() {
    shared actual T echo<T>(T t) given T satisfies Object => t;
}

The way the error message reads is slightly confusing, I think because the backend retains the String upper bound on T in the subtype's refinement of echo.

jvasileff commented 5 years ago

In theory I think this could be allowed if the appropriate bridge method were generated, but it gets tricky because a supertype may already have an overload with a raw signature that conflicts with the necessary bridge method.

gavinking commented 5 years ago

Fixed, thanks for reporting.