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.
When compiling
ceylon.ast.samples
individually, you get the following error:RemoveExtraInfoVisitor
:Node.remove
:As you can see,
remove
puts use-site variance on itskey
parameter’s type, so the error should not occur. However, the model loader loses this information, instead using the typeKey<Object>
, to which the visitor’sKey<out Object>
is not assignable. If you compileceylon.ast.samples
together withceylon.ast.core
, the error vanishes, since the model doesn’t have to be loaded.