eclipse-archived/ceylon

Illegal contravariant refinement allowed on the JVM

Closed this issue · 2 comments

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.

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.

Fixed, thanks for reporting.