bug
bug copied to clipboard
Import renaming incompatible with super, access modifiers, etc
Consider the following code:
object wrap1 {
trait A {
def n = 3
}
}
object wrap2 {
trait A {
def n = 7
}
}
Suppose we want to inherit from both A's above. This produces an error, as expected:
// error: error overriding method n in trait A of type => Int;
// method n in trait A of type => Int needs `override' modifier
trait B extends wrap1.A with wrap2.A
This, of course, is ambiguous
// error: ambiguous parent class qualifier
trait B extends wrap1.A with wrap2.A {
override def n =
super[A].n
}
Oops! This isn't allowed (as per the spec, but it's surprising)
// error: ']' expected but '.' found.
trait B extends wrap1.A with wrap2.A {
override def n =
super[wrap1.A].n
}
But the most surprising thing is that renaming doesn't work!
import wrap1.{A => A1}
import wrap2.{A => A2}
// error: A1 does not name a parent class of trait B
trait B extends A1 with A2 {
override def n =
super[A1].n
}
The same problem arises with access modifiers. Consider:
object Outer {
object A {
object A {
import Outer.{A => RootA}
// error: RootA is not an enclosing class
private[RootA] trait B
}
}
}
Imported From: https://issues.scala-lang.org/browse/SI-1915?orig=1 Reporter: @jorgeortiz85
Still a problem in Scala 3 😞
Users run into this... as pointed out by @som-snytt here: https://users.scala-lang.org/t/invoking-super-in-case-of-identical-name/10114/7