Skip to content

NoSuchMethod error when matching on a private inner class #13256

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
hamdiallam opened this issue Aug 4, 2021 · 3 comments
Closed

NoSuchMethod error when matching on a private inner class #13256

hamdiallam opened this issue Aug 4, 2021 · 3 comments

Comments

@hamdiallam
Copy link

Compiler version: 3.0.1

Minimized code

Scastie Link: https://scastie.scala-lang.org/AL4lT7w7RIuGUBPnhoCoTA

object Monitor {
  def handle(exc: Exception, pf: PartialFunction[Throwable, Unit]): Unit = {
    pf.applyOrElse(exc, { (exc: Exception) =>
      ()
    })
  }
}

class Outer {
  private class MyExc extends Exception
  Monitor.handle(new MyExc, {
      case _: MyExc => println("here")
  })
}

object Main {
  def main(args: Array[String]): Unit = {
    new Test
  }
}

Output (Runtime, not compile time)

java.lang.NoSuchMethodError: Test$MyExc.Test$MyExc$$$outer()LTest;

Expectation

When the inner class is marked private, Dotty will not generate an outer method. Verified this in the byte code. Making MyExc public will have the outer method generated. However, even when private, the bytecode generated in the for the PartialFunctions applyOrElse needs access to the outer instance to when checking to MyExc

Works fine in Scala 2

@smarter
Copy link
Member

smarter commented Aug 4, 2021

Fixed in recent nightlies by #13124

@smarter smarter closed this as completed Aug 4, 2021
@smarter
Copy link
Member

smarter commented Aug 4, 2021

(you can test the latest nightly by setting scalaVersion := "3.0.3-RC1-bin-20210803-010f8de-NIGHTLY")

@hamdiallam
Copy link
Author

Ah thanks, i'll double check the nightlies and issues before creating

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