Skip to content

NoSuchMethodError for field accessor of local class #10856

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

Closed
LPTK opened this issue Apr 29, 2018 · 2 comments
Closed

NoSuchMethodError for field accessor of local class #10856

LPTK opened this issue Apr 29, 2018 · 2 comments
Milestone

Comments

@LPTK
Copy link

LPTK commented Apr 29, 2018

The following code generates a NoSuchMethodError at runtime when using Scala 2.12 but not when using Scala 2.11:

  def transformer(rec_pf: (Tree => Tree) => PartialFunction[Tree, Tree]) =
    new Transformer {
      val pf: PartialFunction[Tree, Tree] = rec_pf(transform) // on Scala 2.12, this raises: java.lang.NoSuchMethodError: squid.utils.meta.UniverseHelpers$$anon$5.pf()Lscala/PartialFunction
      // ^ solved if we make it a def
      override def transform(x: Tree) = pf.applyOrElse(x, super.transform)
    } transform _

Here is the crash reproduced in the REPL:

Welcome to Scala 2.12.5 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_65).
Type in expressions for evaluation. Or try :help.

scala> import scala.reflect.runtime.universe._
import scala.reflect.runtime.universe._

scala> def transformer(...

scala> transformer(k => { case q"0" => q"1" })
res0: reflect.runtime.universe.Tree => reflect.runtime.universe.Tree = $$Lambda$15192/118067290@3ec611bc

scala> res0(q"Some(0).get")
java.lang.NoSuchMethodError: $anon$1.pf()Lscala/PartialFunction;
  at $anon$1.transform(<console>:18)
  at .$anonfun$transformer$1(<console>:19)
  ... 38 elided
LPTK added a commit to epfldata/squid that referenced this issue Apr 30, 2018
The main difficulties in porting the code base to 2.12 were:
 * two compiler bugs introduced by Scala 2.12, reported at:
    - scala/bug#10856
    - scala/bug#10857
 * the limitations of Scala runtime reflection with respect
   to the new encoding of function values (Java 8 lambdas), which
   affected Squid’s reflection-based interpreter
 * a subtle change in the behavior of Scala’s reify{} used by Scalatest,
   which produced an extruded variable when used inside invocations of
   Squid’s rewrite macro
LPTK added a commit to epfldata/squid that referenced this issue Apr 30, 2018
The main difficulties in porting the code base to 2.12 were:
 * two compiler bugs introduced by Scala 2.12, reported at:
    - scala/bug#10856
    - scala/bug#10857
 * the limitations of Scala runtime reflection with respect
   to the new encoding of function values (Java 8 lambdas), which
   affected Squid’s reflection-based interpreter
 * a subtle change in the behavior of Scala’s reify{} used by Scalatest,
   which produced an extruded variable when used inside invocations of
   Squid’s rewrite macro
@howtonotwin
Copy link

howtonotwin commented May 4, 2018

This can be simplified to some more basic types:

def f[A](v: A) = x => {
    (new Function1[A, A] {
      val u = v
      override def apply(x: A) = u
    }).apply(x)
  }
f("")("a")

And the eerie thing is that adding a type signature fixes it:

def f[A](v: A): A => A = ???

hrhino added a commit to hrhino/scala that referenced this issue Oct 10, 2019
@hrhino hrhino added this to the 2.12.8 milestone Oct 10, 2019
lrytz added a commit to scala/scala that referenced this issue Oct 11, 2019
@lrytz
Copy link
Member

lrytz commented Oct 11, 2019

Fixed by scala/scala@9614c3a / scala/scala#7340

@lrytz lrytz closed this as completed Oct 11, 2019
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

5 participants