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
OuterClass.this.type loses type refinement #5130
Comments
Imported From: https://issues.scala-lang.org/browse/SI-5130?orig=1 |
@jsalvata said: A general workaround requires passing this_a.type as a type parameter: scala> class A {
| this_a =>
| def b= new B[this_a.type]
| class B[E >: this_a.type] {
| def a: E= this_a
| }
| }
defined class A
scala> def a= new A {
| def c { }
| }
a: A{def c: Unit}
scala> a.b.a.c
scala> |
@jsalvata said: scala> abstract class A {
| this_a =>
| class B {
| def a: this_a.type= this_a
| }
| def b= new B
| }
defined class A
scala> trait A2 {
| def c { }
| }
defined trait A2
scala> def a= new A with A2
a: A with A2
scala> a.b.a.c
<console>:11: error: value c is not a member of A
a.b.a.c
^ |
@jsalvata said: val pre1 = pre match {
case x: SuperType if sym1.isEffectivelyFinal || sym1.isDeferred =>
x.thistpe
case _: CompoundType if sym1.isClass =>
// sharpen prefix so that it is maximal and still contains the class.
pre.parents.reverse dropWhile (_.member(sym1.name) != sym1) match {
case Nil => pre
case parent :: _ => parent
}
case _ => pre
} I don't see why we want to loose type information of |
@paulp said: |
@jsalvata said (edited on Nov 18, 2011 8:22:43 PM UTC): |
@jsalvata said: |
@odersky said: |
@paulp said: |
@paulp said: |
@retronym said: |
@adriaanm said: |
Checking the type of a.b.a shows why:
Should be A{def c: Unit}
Surprisingly, changing the "def a" into a "val" works around the issue in this particular case:
The text was updated successfully, but these errors were encountered: