diff --git a/compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala b/compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala index 78dc5c43a9ff..99ef281172b4 100644 --- a/compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala +++ b/compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala @@ -144,6 +144,17 @@ trait ImportSuggestions: val timer = new Timer() val deadLine = System.currentTimeMillis() + suggestImplicitTimeOut + // Candidates that are already available without explicit import because they + // are already provided by the context (imported or inherited) or because they + // are in the implicit scope of `pt`. + val alreadyAvailableCandidates: Set[Symbol] = { + val wildProto = wildApprox(pt) + val contextualCandidates = ctx.implicits.eligible(wildProto) + val implicitScopeCandidates = ctx.run.implicitScope(wildProto, ctx).eligible + val allCandidates = contextualCandidates ++ implicitScopeCandidates + allCandidates.map(_.implicitRef.underlyingRef.symbol).toSet + } + /** Test whether the head of a given instance matches the expected type `pt`, * ignoring any dependent implicit arguments. */ @@ -220,7 +231,9 @@ trait ImportSuggestions: Nil roots - .flatMap(_.implicitMembers.filter(shallowTest)) + .flatMap(_.implicitMembers.filter { ref => + !alreadyAvailableCandidates(ref.symbol) && shallowTest(ref) + }) // filter whether the head of the implicit can match .partition(deepTest) // partition into full matches and head matches diff --git a/tests/neg/missing-implicit3.check b/tests/neg/missing-implicit3.check index a33052ef6c9d..3c2ab8ffb83f 100644 --- a/tests/neg/missing-implicit3.check +++ b/tests/neg/missing-implicit3.check @@ -7,8 +7,3 @@ | ord.Ord.ordered[A](/* missing */implicitly[ord.Foo => Comparable[? >: ord.Foo]]) | |But no implicit values were found that match type ord.Foo => Comparable[? >: ord.Foo]. - | - |The following import might make progress towards fixing the problem: - | - | import ord.Ord.ordered - |