Closed
Description
Compiler version
3.3.0
Minimized code
class Foo
class Bar {
implicit val foo: Foo = new Foo
}
object Test {
def main(args: Array[String]): Unit = {
val bar = new Bar
import bar._
implicit val foo: Foo = new Foo
assert(foo == implicitly[Foo])
}
}
Output
java.lang.AssertionError: assertion failed
at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:11)
at Test$.main(Test.scala:14)
at Test.main(Test.scala)
Expectation
I don't expect the wrong implicit to be selected.
The name clash is part of the cause here. With a different name, I expected the more locally defined implicit to win over the wildcard imported one, but that in situation they're actually ambiguous - which is not ideal but it is a little better.
Unimporting, i.e. import bar.{ foo => _, _ }
is a workaround.
Also, it works correctly in Scala 2.