Skip to content
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

Runtime java.lang.NoSuchMethodError when calling a method in anonymous class returning a mixin #22177

Open
jchyb opened this issue Dec 9, 2024 · 1 comment

Comments

@jchyb
Copy link
Contributor

jchyb commented Dec 9, 2024

Compiler version

Scala 2: 2.13.15
Scala 3: 3.3.4

Minimized code

Compiled first with Scala 2:

object Scala2Objects {
  def obj =
    new Quasi {
      def become[T]: T with Quasi = ???
    }
}

trait Quasi {
  def become[T]: T with Quasi
}

Compiled second with Scala 3, depending on the above:

@main def main() =
  Scala2Objects.obj.become

Output

Exception in thread "sbt-bg-threads-63" java.lang.NoSuchMethodError: 'Quasi Quasi.become()'
        at Main$package$.main(Main.scala:2)
        at main.main(Main.scala:1)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:569)
        at sbt.Run.invokeMain(Run.scala:144)
        at sbt.Run.execute$1(Run.scala:94)
        at sbt.Run.$anonfun$runWithLoader$5(Run.scala:121)
        at sbt.Run$.executeSuccess(Run.scala:187)
        at sbt.Run.runWithLoader(Run.scala:121)
        at sbt.Defaults$.$anonfun$bgRunTask$6(Defaults.scala:1988)
        at sbt.Defaults$.$anonfun$termWrapper$2(Defaults.scala:1927)
        at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
        at scala.util.Try$.apply(Try.scala:213)
        at sbt.internal.BackgroundThreadPool$BackgroundRunnable.run(DefaultBackgroundJobService.scala:367)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at java.base/java.lang.Thread.run(Thread.java:840)

Expectation

Not implemented exception

@jchyb jchyb added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Dec 9, 2024
@som-snytt
Copy link
Contributor

I recently noticed a ticket where Scala 2 omits a bridge that Scala 3 correctly implements.

@Gedochao Gedochao added compat:scala2 and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Dec 10, 2024
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

3 participants