Skip to content

Commit ec52017

Browse files
committed
Do not choose implicits that are ambiguous references
Before this commit, implicit_ambiguous_ref.scala failed to compile because the implict search returned `x`, we now always try to typecheck a reference to an identifier before returning it from the implicit search.
1 parent 0ae3ef2 commit ec52017

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ trait Implicits { self: Typer =>
490490
untpd.Apply(untpd.TypedSplice(generated), untpd.TypedSplice(argument) :: Nil),
491491
pt)
492492
val generated1 = adapt(generated, pt)
493-
lazy val shadowing =
493+
val shadowing =
494494
typed(untpd.Ident(ref.name) withPos pos.toSynthetic, funProto)
495495
(nestedContext.addMode(Mode.ImplicitShadowing).setExploreTyperState)
496496
def refMatches(shadowing: Tree): Boolean =
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
object A {
2+
val x: Int = 1
3+
}
4+
5+
abstract class LowPriorityB {
6+
implicit val y: String = "y"
7+
}
8+
9+
object B extends LowPriorityB {
10+
implicit val x: String = "x"
11+
}
12+
13+
object Test {
14+
import A._, B._
15+
def main(args: Array[String]): Unit = {
16+
// B.x is an ambiguous ref, so LowPriorityB.y should be used
17+
println(implicitly[String])
18+
}
19+
}

0 commit comments

Comments
 (0)