Skip to content

AbstractMethodError when implementing a function with a call-by-name parameter #10345

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Atry opened this issue May 31, 2017 · 1 comment
Open

Comments

@Atry
Copy link

Atry commented May 31, 2017

$ 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

Related to #10344, #10362

@SethTisue
Copy link
Member

SethTisue commented Aug 17, 2021

I wondered if this was fixed in Scala 3, but when I tried it in 3.0.2-RC1 I didn't get any farther than:

   |     unwrap(f)
   |            ^
   |            Found:    (f : (=> Unit) => Unit)
   |            Required: Any => Unit

Not sure if anyone wants to poke at this further.

Function values that take by-name parameters are sort of murky and semi-supported, is my impression after looking at tickets such as #9313.

@SethTisue SethTisue added this to the Backlog milestone Aug 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants