Skip to content

Do not choose implicits that are ambiguous references #1141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ trait Implicits { self: Typer =>
untpd.Apply(untpd.TypedSplice(generated), untpd.TypedSplice(argument) :: Nil),
pt)
val generated1 = adapt(generated, pt)
lazy val shadowing =
val shadowing =
typed(untpd.Ident(ref.name) withPos pos.toSynthetic, funProto)
(nestedContext.addMode(Mode.ImplicitShadowing).setExploreTyperState)
def refMatches(shadowing: Tree): Boolean =
Expand Down
1 change: 1 addition & 0 deletions tests/run/implicit_ambiguous_ref.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
y
19 changes: 19 additions & 0 deletions tests/run/implicit_ambiguous_ref.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
object A {
val x: Int = 1
}

abstract class LowPriorityB {
implicit val y: String = "y"
}

object B extends LowPriorityB {
implicit val x: String = "x"
}

object Test {
import A._, B._
def main(args: Array[String]): Unit = {
// B.x is an ambiguous ref, so LowPriorityB.y should be used
println(implicitly[String])
}
}