You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Private field in class cannot be accessed from companion object #8426
According to the announcement of 2.11.0-RC1, I report an issue I have with code that compiles file under 2.10.3 but does not compile under 2.11.0-RC1.
The issue can be reduced to the following minimal case:
Welcome to Scala version 2.10.3 (JavaHotSpot(TM) 64-BitServerVM, Java1.7.0_51).
Type in expressions to have them evaluated.
Type:help for more information.
scala>:paste
// Entering paste mode (ctrl-D to finish)objectAextendsAclassA {
privatevara:Boolean=falsedefrun { A.a =true }
}
// Exiting paste mode, now interpreting.
defined module A
defined classA
scala>
The same code fails to compile with Scala 2.11.0-RC1
Welcome to Scala version 2.11.0-RC1 (JavaHotSpot(TM) 64-BitServerVM, Java1.7.0_51).
Type in expressions to have them evaluated.
Type:help for more information.
scala>:paste
// Entering paste mode (ctrl-D to finish)objectAextendsAclassA {
privatevara:Boolean=falsedefrun { A.a =true }
}
// Exiting paste mode, now interpreting.
<console>:10:error: value a is not a member of objectAdefrun { A.a =true }
^
scala>
This was changed under #7475. We double checked with Martin, and with the behaviour of Javac, which does the same thing. (Java doesn't have companions, but you can emulate the same thing with nested classes)
Activity
scabug commentedon Mar 17, 2014
Imported From: https://issues.scala-lang.org/browse/SI-8426?orig=1
Reporter: Tobias Roeser (lefou)
Affected Versions: 2.11.0-RC1
See #7475
scabug commentedon Mar 18, 2014
@retronym said (edited on Mar 18, 2014 12:03:09 AM UTC):
Thanks a lot or reporting.
As weird as this seems, it is actually according to the Spec.
Private fields are not inherited. So you can't select them from a value of the derived type.
You can upcast and select the member, however.
This was changed under #7475. We double checked with Martin, and with the behaviour of Javac, which does the same thing. (Java doesn't have companions, but you can emulate the same thing with nested classes)
scabug commentedon Mar 18, 2014
@adriaanm said:
I'm adding a paragraph to the release notes with the example from #8371, which is the smallest I've seen so far.
scabug commentedon Mar 18, 2014
Tobias Roeser (lefou) said:
Thank you! As this was a bug in 2.10.3, will it be fixed in 2.10.4, too?
scabug commentedon Mar 18, 2014
@retronym said:
No, the 2.10.x series will stay bug compatible.