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
private vals in traits depend on composition order #261
Comments
Imported From: https://issues.scala-lang.org/browse/SI-261?orig=1 |
@michelou said: |
@odersky said: |
Jrg Kubitz (jukz) said: trait a { |
Matt Hellige (hellige) said: In the test case, the order of the declarations of A and B are switched between the two versions: trait A ...
trait B ... vs trait B ...
trait A ... But this has nothing to do with the bug!! The important change is the order of A and B in the declaration of Test: object Test extends Application with A with B ...
object Test extends Application with B with A ... // this one fails! In 2.8 final, it remains the case that this works correctly in the interpreter, and incorrectly in the compiler. There seems to be no change in behavior since the bug was opened. The original transcript I included when I opened the bug is still what I see with the new release. Sorry to have to reopen this very old bug! |
Matt Hellige (hellige) said: object Test extends Application with A with B ... // THIS one fails...
object Test extends Application with B with A ... Sorry for all the confusion, it is actually the first one ("A with B") which fails, as in the original bug. In the test case, both versions have "B with A". |
@paulp said: That test case is seriously braindamaged. I'm not in the habit of checkin in no-op test cases, don't know what spell I was under. |
@adriaanm said: |
@adriaanm said: |
@adriaanm said: |
@adriaanm said (edited on Feb 12, 2014 3:51:25 AM UTC): Verified to work with scalac from scala/scala#3440. $ pr_dist 3440
$ /Users/adriaan/git/scala-dist/target/universal/stage/bin/scalac /Users/adriaan/Desktop/bugs/t261/Test.scala
# WOOHOO
$ scalac -version
Scala compiler version 2.11.0-M7 -- Copyright 2002-2013, LAMP/EPFL
$ scalac /Users/adriaan/Desktop/bugs/t261/Test.scala:8: error: value foo in trait B cannot be accessed in object Test
println(foo)
^
one error found
$ cat /Users/adriaan/Desktop/bugs/t261/Test.scala
trait A { val foo: String = "A" }
trait B {
private val foo: String = "B"
def f = println(foo)
}
object Test extends A with B {
def main(args: Array[String]) = {
println(foo)
f
}
}
$ /Users/adriaan/git/scala-dist/target/universal/stage/bin/scala Test
A
B PS: https://github.com/adriaanm/binfu/blob/master/scafu.sh#L41 |
@adriaanm said (edited on Feb 12, 2014 3:59:46 AM UTC): |
Matt Hellige (hellige) said: |
(From [http://www.nabble.com/private-vals-in-traits--t4780372.html this mailing list thread])
Consider:
This looks, good, but if I switch the order of B and A in the
declaration of Test, it doesn't compile, claiming that there's no such
value as foo.
Adriaan pointed out that this works in the interpreter, and I replied:
Interesting. I see now that it works in the interpreter (I hadn't
tried). But it does not work with scalac:
I would expect this to work in the compiler as it works in the interpreter. If this is not a compiler defect, I would also expect it to fail in the interpreter. (The above session is with 2.6.0, but the behavior is the same in 2.6.1-RC1.)
The text was updated successfully, but these errors were encountered: