Closed
Description
The following code fails (it compiles if we remove rewrite
):
class Test {
rewrite def foo(x: Int = 5)(implicit y: Int): Int =
if (x > 0) y * y
else y + y
implicit val m: Int = 7
(new Test).foo()
}
Error message:
-- Error: examples/implicit.scala:8:13 -----------------------------------------
8 | (new Test).foo()
| ^^^^^^^^^^^^^^
| method foo is declared as erased, but is in fact used
It's due to the tree generated where Apply.fun
is Block
:
class Test() extends Object() {
rewrite def foo(x: Int)(implicit y: Int): Int =
if x.>(0) then y.*(y) else y.+(y)
def foo$default$1: Int = 5
implicit val m: Int = 7
{
val $1$: Test = new Test()
$1$.foo($1$.foo$default$1)
}(this.m)
}
@odersky I'm wondering if it's possible to enforce the invariant that Apply.fun
is never a Block
.