-
Notifications
You must be signed in to change notification settings - Fork 21
abstract types lose their prefix #6161
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-6161?orig=1 |
@retronym said (edited on Aug 1, 2012 8:44:41 AM UTC): object t6161 {
trait N {
type Name
}
trait N1 extends N {
class Name {
type ThisNameType <: Name
def encode: ThisNameType = ???
}
}
trait S {
self: N => // change to N1 and it compiles
type NameType <: Name
}
object g extends S with N1
val n1: g.NameType = ???
val n2: g.Name = n1.encode
}
This fails uniformly in all versions of Scala that I have at hand. |
@paulp said: |
@retronym said: https://gist.github.com/4674756 Presented as-is and free of conclusions. |
@retronym said:
|
@paulp said: Almost ANY place we call dealiasWiden, it is possible that if we followed this third avenue of progress ("is this an abstract type with an upper bound?") we would discover the type which makes the condition true. This leads to the increasingly ridiculous def dealiasWidenUpperBoundChain: List[Type] Over to you... |
@retronym said (edited on Apr 28, 2013 7:23:09 AM UTC): trait A {
type Element<:Elt
trait Elt {
def doIt(x:Int):Int
def child(e:Element):Unit
}
}
class A1 extends A {
class Element extends Elt {
def doIt(x:Int):Int = x+3
def child(e:Element):Unit = ()
}
}
class A2 extends A1 {
class Element extends super.Element {
override def doIt(x:Int):Int = super.doIt(x)+1
override def child(e:Element):Unit = super.child(e)
}
}
If it proves to be a separate issue, we could spawn a new ticket. |
@paulp said: If it seems unsound, it's because it is. |
@paulp said: override def child(e: A2.super.Element):Unit = super.child(e) Then the signatures match and the override is fine, but we have a different and also true error:
...because the method signature in A2#Element no longer matches the abstract signature defined in A#Elt. Just for fun I will call super.child from THAT method so we can see all the types at play. This compiles. trait A {
type Element<:Elt
trait Elt {
def doIt(x:Int):Int
def child(e:Element):Unit
}
}
class A1 extends A {
class Element extends Elt {
def doIt(x:Int):Int = x+3
def child(e: A1.this.Element):Unit = ()
}
}
class A2 extends A1 {
class Element extends super.Element {
override def doIt(x:Int):Int = super.doIt(x)+1
override def child(e: A2.super.Element):Unit = super.child(e)
def child(e: A2.this.Element):Unit = super.child(e: A2.super.Element)
}
} |
@gkossakowski said: |
@paulp said: package p {
trait N { type Name ; def make(): Name }
trait N1 extends N { class Name ; def make(): Name = new Name }
trait N2 extends N { class Name }
object g extends App with N1 with N2 {
val x = (this: N2).make()
// java.lang.ClassCastException: p.N1$Name cannot be cast to p.N2$Name
}
} Until we're talking about a language where object g doesn't freely discard information about the types of its inherited members, or where the type x.Name doesn't fluctuate depending on the static type of x, there's no way to draw sound inferences based on the way an abstract type is refined in a trait. |
@adriaanm said: |
@retronym said: |
@Blaisorblade said:
+1. I'm also deeply confused by the suggestion in this warning: scala> trait A { type A = Int }; class B extends A { type A = String }
<console>:10: error: overriding type A in trait A, which equals Int;
type A needs `override' modifier
trait A { type A = Int }; class B extends A { type A = String }
^ Does it ever make sense to override a type alias? I can still understand |
@paulp said: Removing an override: % ./build/pack/bin/scalac src/reflect/scala/reflect/internal/StdNames.scala
src/reflect/scala/reflect/internal/StdNames.scala:228: error: overriding type NameType in trait TypeNamesApi, which equals StdNames.this.TypeName;
type NameType needs `override' modifier
type NameType = TypeName
^
one error found |
@adriaanm said: |
If I change the definition of encode in Names to
def encode: Name with ThisNameType
then this compiles, which should make it definitive that this is a bug given thatThisNameType <: Name
.The text was updated successfully, but these errors were encountered: