-
Notifications
You must be signed in to change notification settings - Fork 21
Anonymous classes methods becoming private when compiled. #9487
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
Comments
Imported From: https://issues.scala-lang.org/browse/SI-9487?orig=1 |
@sjrd said: |
@sjrd said: It is also worth mentioning that if the anonymous class does not have any expected type at all, then the members are kept public. For example rewriting def get(): AnyRef = {
val o = new { ... }
o
} allows all members to be public. |
This came up recently because the private members can be reported unused in Scala 2. Scala 3 has to do extra work to decide if a member is "effectively private". Is it OK to close this as out of scope a decade later? Scala 3 made a different choice, but Scala 2 is unlikely to change. |
Yes, let's close. |
When a type of an anonymous class is less specific that the definition of the class (AnyRef for example) the anonymous class methods become private. This happens with val, def and var definition inside the class.
It looks like a code pattern that should be avoided, but in Scala.js this is used to create javascript objects. scala-js/scala-js#1899
The text was updated successfully, but these errors were encountered: