AbstractMethodError when implementing a function with a call-by-name parameter #10345
Open
Description
$ scala
Welcome to Scala 2.12.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_131).
Type in expressions for evaluation. Or try :help.
scala> val byNameContainer = {
| def unwrap[ByName0[_]](f: ByName0[Unit] => Unit): { type ByName[A] = ByName0[A] } = {
| new {
| type ByName[A] = ByName0[A]
| }
| }
| val f: (=> Unit) => Unit = { _ =>
| ()
| }
| unwrap(f)
| }
<console>:12: warning: higher-kinded type should be enabled
by making the implicit value scala.language.higherKinds visible.
This can be achieved by adding the import clause 'import scala.language.higherKinds'
or by setting the compiler option -language:higherKinds.
See the Scaladoc for value scala.language.higherKinds for a discussion
why the feature should be explicitly enabled.
def unwrap[ByName0[_]](f: ByName0[Unit] => Unit): { type ByName[A] = ByName0[A] } = {
^
byNameContainer: AnyRef{type ByName[A] = => A} = $anon$1@598260a6
scala>
scala> type ByName[A] = byNameContainer.ByName[A]
defined type alias ByName
scala>
scala> trait RefinementFunction {
| type Parameter
|
| def apply(parameter: Parameter): Unit
| }
defined trait RefinementFunction
scala>
scala> val f = new RefinementFunction {
| type Parameter = ByName[String];
| def apply(v1: => String): Unit = {}
| }
f: RefinementFunction{type Parameter = ByName[String]} = $anon$1@5cb042da
scala>
| f("x")
java.lang.AbstractMethodError: $anon$1.apply(Ljava/lang/Object;)V
... 30 elided