Skip to content

Scala 2 regression: free-form names in backticks crash at runtime #12729

@j-mie6

Description

@j-mie6

Compiler version

With 3.0.0 (or 3.0.1-RC1 on scastie)

Minimized code

object foo {
  val `<x>` = "hello!"
  def main(args: Array[String]): Unit = println(`<x>`)
}

Output

In scastie this gives:

java.lang.ClassFormatError: Method "<x>" in class foo has illegal signature "()Ljava/lang/String;"
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:757)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
	at sbt.internal.ManagedClassLoader.findClass(ManagedClassLoader.java:102)
	at sbt.internal.BottomClassLoader.lambda$findClass$0(BottomClassLoader.java:56)
	at sbt.internal.ClassLoadingLock.withLock(ClassLoadingLock.java:29)
	at sbt.internal.BottomClassLoader.findClass(BottomClassLoader.java:51)
	at sbt.internal.BottomClassLoader.loadClass(BottomClassLoader.java:66)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:348)
	at sbt.Run.getMainMethod(Run.scala:150)
	at sbt.Run.execute$1(Run.scala:81)
	at sbt.Run.$anonfun$runWithLoader$5(Run.scala:110)
	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
	at sbt.util.InterfaceUtil$$anon$1.get(InterfaceUtil.scala:17)
	at sbt.TrapExit$App.run(TrapExit.scala:258)
	at java.lang.Thread.run(Thread.java:748)

I've also seen it give something like:

java.lang.ClassFormatError: Illegal method name "<expr>"

Expectation

Since (fun) names like this worked fine in 2.13, I'd expect them to work fine in 3 too... perhaps they used to be name mangled?

This form in particular using <name> is useful for giving names to grammar rules in parsers.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions