Open
Description
minimized code
Given a compilation unit:
package p.q
class X {
override def toString() = "p.q.X"
}
Either of these references to X
should be ambiguous:
import reflect.ClassTag
package p {
class X {
override def toString() = "p.X"
}
package q {
object Test {
def f = implicitly[ClassTag[X]] // ambiguous
}
}
object Test {
def main(args: Array[String]) = println {
p.q.Test.f
}
}
}
or
import reflect.ClassTag
package p {
class X {
override def toString() = "p.X"
}
package q {
import r.X
object Test {
def f = implicitly[ClassTag[X]] // ambiguous
}
}
package r {
class X {
override def toString() = "p.r.X"
}
}
object Test {
def main(args: Array[String]) = println {
p.q.Test.f
}
}
}
Compilation output
➜ scala git:(2.13.x) skalac test/files/neg/t10662/*.scala
test/files/neg/t10662/px_2.scala:19: error: reference to X is ambiguous;
it is both defined in package p and available as class X in package q
implicitly[T[X]] // ambiguous
^
1 error
➜ scala git:(2.13.x) skalac test/files/neg/t10662b/*.scala
test/files/neg/t10662b/px_2.scala:16: error: reference to X is ambiguous;
it is both defined in package p and imported subsequently by
import r.X
implicitly[T[X]] // ambiguous
^
1 error
It compiles on both Scala 2.13.0 and 3, but Scala 2 picks p.q.X
and p.r.X
respectively, and Dotty picks p.X
in both cases.
expectation
p.q.X
has lowest precedence: it is made available by the packaging package q
but cannot shadow the high priority definition p.X
, and is therefore ambiguous.
Similarly for the import r.X
, as imports never shadow definitions in the current file.