File tree Expand file tree Collapse file tree 2 files changed +14
-6
lines changed
compiler/src/dotty/tools/dotc/typer Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -144,6 +144,17 @@ trait ImportSuggestions:
144144 val timer = new Timer ()
145145 val deadLine = System .currentTimeMillis() + suggestImplicitTimeOut
146146
147+ // Candidates that are already available without explicit import because they
148+ // are already provided by the context (imported or inherited) or because they
149+ // are in the implicit scope of `pt`.
150+ val alreadyAvailableCandidates : Set [Symbol ] = {
151+ val wildProto = wildApprox(pt)
152+ val contextualCandidates = ctx.implicits.eligible(wildProto)
153+ val implicitScopeCandidates = ctx.run.implicitScope(wildProto, ctx).eligible
154+ val allCandidates = contextualCandidates ++ implicitScopeCandidates
155+ allCandidates.map(_.implicitRef.underlyingRef.symbol).toSet
156+ }
157+
147158 /** Test whether the head of a given instance matches the expected type `pt`,
148159 * ignoring any dependent implicit arguments.
149160 */
@@ -220,7 +231,9 @@ trait ImportSuggestions:
220231 Nil
221232
222233 roots
223- .flatMap(_.implicitMembers.filter(shallowTest))
234+ .flatMap(_.implicitMembers.filter { ref =>
235+ ! alreadyAvailableCandidates(ref.symbol) && shallowTest(ref)
236+ })
224237 // filter whether the head of the implicit can match
225238 .partition(deepTest)
226239 // partition into full matches and head matches
Original file line number Diff line number Diff line change 77 | ord.Ord.ordered[A](/* missing */implicitly[ord.Foo => Comparable[? >: ord.Foo]])
88 |
99 |But no implicit values were found that match type ord.Foo => Comparable[? >: ord.Foo].
10- |
11- |The following import might make progress towards fixing the problem:
12- |
13- | import ord.Ord.ordered
14- |
You can’t perform that action at this time.
0 commit comments