I have
class Foo[A] {
def foo[B](x: A, y: B) = y
}
class Bar[A] extends Foo[A] {
override def foo[B](x: A, y: B) = superCall
}
where the superCallwhite box macro should expand to super.foo[B](x, y), and it shows -Ymacro-debug-lite. The problem is that it cannot compile with the following error:
[error] /home/aromanov/IdeaProjects/scala-dry/src/test/scala/com/github/alexeyr/scaladry/SuperTests.scala:80: type mismatch;
[error] found : y.type (with underlying type B)
[error] required: B
[error] override def foo[B](x: A, y: B) = superCall
[error] ^
This makes no sense to me: y.typenarrower than B, therefore, if it is found when required B, this should not be a mistake. Even a stranger, if I replaced with the superCallextension super.foo[B](x, y), the error will disappear!
superCall(slightly simplified by removing irrelevant conditional expressions, you can see the full version on Github ):
def superCall: Tree = {
val method = c.internal.enclosingOwner.asMethod
val args = method.paramLists.map(_.map(sym => c.Expr(q"$sym")))
val typeParams = method.typeParams.map(_.asType.name)
q"super.${method.name.toTermName}[..$typeParams](...$args)"
}
EDIT: add -uniqidshows
[error] found : y#26847.type (with underlying type B#26833)
[error] required: B#26834
[error] override def foo[B](x: A, y: B) = superCall
[error] ^
[error] one error found
, , , 2 B . B C, Foo.foo B, C , C.
2: . Scala typer , . typer (super.foo[B](x, y) superCall)
class Foo#26818[A#26819] extends scala#22.AnyRef#2757 {
def <init>#26822(): Foo#26818[A#26819] = {
Foo#26818.super.<init>#3104();
()
};
def foo#26823[B#26824](x#26827: A#26819, y#26828: B#26825): B#26824 = y#26828
};
class Bar#26820[A#26821] extends Foo#26818[A#26821] {
def <init>#26831(): Bar#26820[A#26821] = {
Bar#26820.super.<init>#26822();
()
};
override def foo#26832[B#26833](x#26836: A#26821, y#26837: B#26834): B#26833 = Bar#26820.super.foo#26823[B#26834](x#26836, y#26837)
};
, superCall Bar#26820.super.foo#26823[B#26833](x#26836, y#26837).