-
Notifications
You must be signed in to change notification settings - Fork 21
Private member shadows inherited member #7475
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-7475?orig=1 |
@paulp said: Here's a test. This should compile and when run print 2 twice. trait A { private val x = 1 }
trait B { val x = 2 }
trait C1 extends B with A { println(x) }
trait C2 extends A with B { println(x) }
object Test {
def main(args: Array[String]): Unit = {
new C1 { }
new C2 { }
}
} |
Rob Norris (rnorris) said: trait C3 extends B { self: A => println(x) } Not sure if this is surprising or not. Another data point. |
@retronym said: In regular compilation (joint or separate); the member def searchPrefix = {
cx = cx.enclClass
val found0 = lookupInPrefix(name)
val found1 = found0 filter accessibleInPrefix
if (found0.exists && !found1.exists && inaccessible == null)
inaccessible = LookupInaccessible(found0, analyzer.lastAccessCheckDetails)
found1
} In the resident compilation context (e.g. REPL with classes defined line-by-line), the name mangling of (baseClasses(1), baseClasses(1).info.decls.toList(1), baseClasses(1).info.decls.toList(1).name)
result = {scala.Tuple3@7304}"(trait A#45776,value x#45779,$line4$$read$$iw$$iw$A$$x)" The lookup walks further up the base class sequence, finds We're all to well aware of the proliferation of this sort of subtle bug in resident compilers; that's why we aren't supporting FSC anymore. But what do to with the beloved REPL. Could we rig it up to reload symbols from classfiles after they have compiled, rather than hanging onto the renmants of the later phases of the original run? Back to the question of whether the error is valid or not under regular conditions. I hope not.
So the following is a bug, no? B should not have inherited scala> class A {
| private val a: Int = 0
| class B extends A {
| def foo(a: A) = a.a // okay
| println(this.a) // wait, what?
| }
| }
defined class A |
@retronym said: trait AbstractPublic {
def queue: Any
}
trait ConcretePrivate {
private val queue: Any = ()
}
abstract class Mix
extends ConcretePrivate with AbstractPublic {
final def queue: Any = ()
} |
@retronym said: trait T {
type TT = T with Any
private val priv = 0
(??? : TT).priv // we currently allow this, and should continue to do so.
} Collateral work: I just noticed that |
@paulp said: |
@gkossakowski said: |
@som-snytt said: |
@retronym said: class A {
private val foo = 1
(new B).foo // refchecks, but should not
}
class B extends A |
@retronym said (edited by @adriaanm on Feb 10, 2014 12:46:50 AM UTC): |
@retronym said: |
@adriaanm said: |
@retronym said: % git diff
diff --git a/test/files/pos/t7475f.scala b/test/files/pos/t7475f.scala
index 45a4000..275d997 100644
--- a/test/files/pos/t7475f.scala
+++ b/test/files/pos/t7475f.scala
@@ -6,6 +6,7 @@ class C {
private def foo: Any = 0
this match {
case d: D =>
+ d: String
d.foo
}
}
% qbin/scalac test/files/pos/t7475f.scala
test/files/pos/t7475f.scala:9: error: type mismatch;
found : C with D
required: String
d: String But that's less of a WTF than not being able to access the private member of the refined type of a binder, so if we're after a simple change that's okay with me. |
@adriaanm said: |
@adriaanm said: def makeTypedUnApply() = {
// the union of the expected type and the inferred type of the argument to unapply
val glbType = glb(ensureFullyDefined(pt) :: unapplyArg.tpe_* :: Nil) |
@adriaanm said: |
@adriaanm said: |
@adriaanm said: |
Depending on order of traits, private members can shadow inherited members and prevent compilation. This does not happen with separate compilation.
Expected behavior (to me anyway) is that private members (which are not inherited) should not shadow inherited members when resolving symbols in subclasses. But in either case behavior should be consistent between combined and separate compilation.
Edit: damn this editor/formatter.
The text was updated successfully, but these errors were encountered: