Skip to content
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

Closed
scabug opened this issue Dec 1, 2007 · 15 comments
Closed

private vals in traits depend on composition order #261

scabug opened this issue Dec 1, 2007 · 15 comments

Comments

@scabug
Copy link

scabug commented Dec 1, 2007

(From [http://www.nabble.com/private-vals-in-traits--t4780372.html this mailing list thread])

Consider:

 trait A { val foo: String = "A" }
 trait B {
   private val foo: String = "B"
   def f = println(foo)
 }
 object Test extends Application with B with A {
   println(foo) // prints "A", as expected
   f            // prints "B", as expected
 }

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:

[~]% cat 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 {
   println(foo)
   f
}
[~]% scalac test.scala
test.scala:7: error: not found: value foo
   println(foo)
           ^
one error found
[~]% scalac -version
Scala compiler version 2.6.0-final -- (c) 2002-2007 LAMP/EPFL
[~]% scala
Welcome to Scala version 2.6.0-final.
Type in expressions to have them evaluated.
Type :help for more information.

scala> :load test.scala
Loading test.scala...
defined trait A
defined trait B
defined module Test

scala> Test
A
B
res0: Test.type = Test$$@7b37df

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.)

@scabug
Copy link
Author

scabug commented Dec 1, 2007

Imported From: https://issues.scala-lang.org/browse/SI-261?orig=1
Reporter: Matt Hellige (hellige)
See #7475

@scabug
Copy link
Author

scabug commented Dec 18, 2007

@michelou said:
Compiler and interpreter should behave the same.

@scabug
Copy link
Author

scabug commented Jan 14, 2009

@odersky said:
Milestone next_bugfix deleted

@scabug
Copy link
Author

scabug commented Nov 5, 2009

Jrg Kubitz (jukz) said:
using Eclipse 3.5.1 scala plugin 2.7.7.final, Windows XP
this doesnt work either (may be the same bug):

trait a {
private[this] val a:Int=3
}
trait b {
private[this] val a:Int=3
}
class c extends a with b { //compiler crahses
}

@scabug
Copy link
Author

scabug commented Jul 3, 2010

@paulp said:
(In r22482) Test case closes #261, no review.

@scabug
Copy link
Author

scabug commented Jul 15, 2010

Matt Hellige (hellige) said:
I'm sorry, this bug still exists in 2.8 final. If you look carefully at the test case, you will see that it tests the wrong thing!

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!

@scabug
Copy link
Author

scabug commented Jul 15, 2010

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".

@scabug
Copy link
Author

scabug commented Jan 14, 2011

@paulp said:
trac has some funny ideas about who to email when; I get tons of pointless emails about people being added to cc lists, but nothing about this ticket being reopened even though I closed it.

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.

@scabug
Copy link
Author

scabug commented Mar 15, 2013

@adriaanm said:
Un-assigning to foster work stealing, as announced in https://groups.google.com/forum/?fromgroups=#!topic/scala-internals/o8WG4plpNkw

@scabug
Copy link
Author

scabug commented Jul 10, 2013

@adriaanm said:
Unassigning and rescheduling to M6 as previous deadline was missed.

@scabug
Copy link
Author

scabug commented Jan 27, 2014

@adriaanm said (edited on Jan 27, 2014 8:17:37 PM UTC):
See also slight variation in #7699 (marked as duplicate)

@scabug
Copy link
Author

scabug commented Feb 10, 2014

@adriaanm said:
Let;s see if Jason's fixes to findMember resolved this one. Otherwise, probably need to bump to 2.12

@scabug
Copy link
Author

scabug commented Feb 12, 2014

@adriaanm said (edited on Feb 12, 2014 3:51:25 AM UTC):
Yep!! Chalk up another three-digit bug for mr. Zaugg!

Verified to work with scalac from scala/scala#3440.
I'll submit a PR with the test case.

$ 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

@scabug
Copy link
Author

scabug commented Feb 12, 2014

@adriaanm said (edited on Feb 12, 2014 3:59:46 AM UTC):
Test in scala/scala#3512

@scabug scabug closed this as completed Feb 12, 2014
@scabug
Copy link
Author

scabug commented Feb 15, 2014

Matt Hellige (hellige) said:
Incredible! It almost makes me sad to see this one closed... ;)

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