Skip to content

Lifted anonymous classes clash with non anonymous ones #3051

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
nicolasstucki opened this issue Sep 1, 2017 · 2 comments
Closed

Lifted anonymous classes clash with non anonymous ones #3051

nicolasstucki opened this issue Sep 1, 2017 · 2 comments

Comments

@nicolasstucki
Copy link
Contributor

class Foo {
  class $anon$1
  new Object { }
}

As the unique name generator does not know about the name on class $anon$1, it will give the same name to the class for new Object { }. The result is a corrupted scope where both names refer to the same symbol and get stuck in an infinite loop.

Same for methods

class Foo {
  def foo = {
    def f() = ()
    f()
  }
  def f$1() = ()
}

There are two possible solutions

  • Disallow names
  • Register all relevant names for classes and methods in the map of the FreshNameCreator

Which one should we choose? I am more inclined to the first one as it simplifies the interaction with #2999

scalac has the same issue scala/bug#10492

@nicolasstucki
Copy link
Contributor Author

As mentioned in the language specifications the $ are reserved by the compiler (http://scala-lang.org/files/archive/spec/2.12/01-lexical-syntax.html). We should add warnings/errors when using such identifiers.

@odersky
Copy link
Contributor

odersky commented Jan 7, 2018

The current wording in the spec is something like this: "Names with $'s in them are reserved, and should not be used in programs. If a program does use such names the results are unspecified". I think we should not try to change this.

@odersky odersky closed this as completed Jan 7, 2018
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