Skip to content

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

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
j-mie6 opened this issue Jun 6, 2021 · 3 comments · Fixed by #12901
Closed

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

j-mie6 opened this issue Jun 6, 2021 · 3 comments · Fixed by #12901
Assignees
Milestone

Comments

@j-mie6
Copy link

j-mie6 commented Jun 6, 2021

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.

@smarter
Copy link
Member

smarter commented Jun 6, 2021

Huh, name encoding kicks in for val `<` , val `<>` , val `<a` , and val `a>` , but not val `<a>` , I don't know why.

@j-mie6
Copy link
Author

j-mie6 commented Jun 6, 2021

perhaps it's similar to an xml literal?

@smarter
Copy link
Member

smarter commented Jun 6, 2021

Looks like a poor attempt at dealing with <init>/<clinit>: https://github.com/lampepfl/dotty/blob/f1252d8f83ace1561c8f53e132ef94c75be9d287/compiler/src/dotty/tools/dotc/core/Names.scala#L344-L346

@smarter smarter self-assigned this Jun 6, 2021
@anatoliykmetyuk anatoliykmetyuk assigned sjrd and unassigned smarter Jun 22, 2021
sjrd pushed a commit to dotty-staging/dotty that referenced this issue Jun 22, 2021
In addition, reject `<init>` and `<clinit>` in the parser, so that
users don't write them in source code.
@sjrd sjrd assigned sjrd and unassigned sjrd Jun 22, 2021
mlachkar added a commit to mlachkar/dotty that referenced this issue Jun 24, 2021
In addition, reject `<init>` and `<clinit>` in the parser, so that
users don't write them in source code.
mlachkar added a commit to mlachkar/dotty that referenced this issue Jun 24, 2021
In addition, reject `<init>` and `<clinit>` in the parser, so that
users don't write them in source code.
mlachkar added a commit to mlachkar/dotty that referenced this issue Jun 24, 2021
In addition, reject `<init>` and `<clinit>` in the parser, so that
users don't write them in source code.
bishabosha added a commit that referenced this issue Jun 25, 2021
Fix #12729: Don't encode <init> and <clinit> only.
@Kordyjan Kordyjan added this to the 3.0.2 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants