ceylon / ceylon-js

DEPRECATED
Apache License 2.0
54 stars 9 forks source link

Use-site variance of parameters is lost by model loader #579

Closed lucaswerkmeister closed 9 years ago

lucaswerkmeister commented 9 years ago

When compiling ceylon.ast.samples individually, you get the following error:

argument must be assignable to parameter key of remove in Node: Key<out Object> is not assignable to Key<Object> at 13:24-13:26 of RemoveExtraInfoVisitor.ceylon

RemoveExtraInfoVisitor:

shared class RemoveExtraInfoVisitor(Key<out Object>+ keys)
        satisfies Visitor {
    shared actual void visitNode(Node that) {
        for (key in keys) {
            that.remove(key);
        }
        that.visitChildren(this);
    }
}

Node.remove:

shared Type? remove<Type>(Key<out Type> key)
        given Type satisfies Object {
    assert (is Type? ret = extraInfo.remove(key.id));
    return ret;
}

As you can see, remove puts use-site variance on its key parameter’s type, so the error should not occur. However, the model loader loses this information, instead using the type Key<Object>, to which the visitor’s Key<out Object> is not assignable. If you compile ceylon.ast.samples together with ceylon.ast.core, the error vanishes, since the model doesn’t have to be loaded.

lucaswerkmeister commented 9 years ago

Thanks!