Open
Description
reproduction steps
Minimized example:
package example
import scala.util.Try
class X(a: Any)
final class XImpl
extends X({
def res = Try(helper())
def helper() = ()
res
})
problem
The above fails to compile with an error:
Error:(10, 19) Implementation restriction: access of method helper$1 from <$anon: Function0>, would require illegal premature access to the unconstructed `this` of class XImpl in package example
def res = Try(helper())
However, the error can be worked around by enclosing the block in a redundant function with ().pipe { _ => ... }
, in which case it will compile and work as expected at runtime:
package example
import scala.util.Try
import scala.util.chaining._
class X(a: Any)
final class XImpl
extends X(().pipe { _ =>
def res = Try(helper())
def helper() = ()
res
})
Which shows that the code doesn't actually trigger an implementation restriction.
expectation
Expected it to compile. This bug affects classes that pass an effect value or a block of code to the superconstructor such as this. dotty is not affected.