You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Clone of scala/bug#12209 - I thought it's worth reporting here as well because it looks like a problematic interaction of language features: overriding + overloading + traits + variance.
Minimized code
objectOverrideCheckextendsApp {
traitA { defm(x: CharSequence):String=s"A: $x" }
//trait B extends A { override def m(x: String): String = s"B: $x" } // no: m has a different signaturetraitC[-T<:CharSequence] { defm(x: T):String=s"C: $x" }
//trait D extends C[String] { def m(x: String): String = "D" } // no: m needs override modifiertraitDextendsC[String] { overridedefm(x: String):String=s"D: $x" } // okvalx=newDwithC[CharSequence] // ok: String <: CharSequence, C[CharSequence] <: C[String]
println(x.m("x1")) // ok: D
println((x: C[String]).m("x2")) // bad: Cvaly=newD {}
println(y.m("y1")) // ok: D
println((y: C[String]).m("y2")) // ok: D
}
I'm not sure if it's possible to observe this problem with a covariant trait.
Output
D: x1
C: x2
D: y1
D: y2
Expectation
I am not sure. I guess I shouldn't be able to define x.
I guess the problem is that we do the override check during method declaration, but the example shows that we can't know for sure at this point of time. Is it viable to do the override check for all members during class definition?
The text was updated successfully, but these errors were encountered:
Uh oh!
There was an error while loading. Please reload this page.
Clone of scala/bug#12209 - I thought it's worth reporting here as well because it looks like a problematic interaction of language features: overriding + overloading + traits + variance.
Minimized code
I'm not sure if it's possible to observe this problem with a covariant trait.
Output
Expectation
I am not sure. I guess I shouldn't be able to define
x
.I guess the problem is that we do the override check during method declaration, but the example shows that we can't know for sure at this point of time. Is it viable to do the override check for all members during class definition?
The text was updated successfully, but these errors were encountered: