Skip to content

Unsound code emitted to instantiate a inner class (defined in Java) #10838

Closed
@dwijnand

Description

@dwijnand

Minimized code

public class A {
  public class B {}
}
object Test {
  def main(args: Array[String]): Unit = {
    val a = new A
    new a.B
  }
}

Output

$ echo 'public class A { public class B {} }' > A.java &&
>   echo 'object Test { def main(args: Array[String]): Unit = { val a = new A; new a.B } }' > Test.scala &&
>   scalac3 A.java Test.scala &&
>   javac A.java &&
>   scala3 Test
Exception in thread "main" java.lang.NoSuchMethodError: A$B: method 'void <init>()' not found
	at Test$.main(Test.scala:1)
	at Test.main(Test.scala)

Expectation

No boom. Discovered while testing MiMa with Scala 3 (there was a test that asserts that making an inner class a nested class (by making it static) is binary incompatible). This one I consider pretty serious. The equivalent in Scala works, so perhaps it needn't be a blocker for 3.0?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions