File tree 2 files changed +20
-13
lines changed
compiler/src/dotty/tools/dotc/typer
2 files changed +20
-13
lines changed Original file line number Diff line number Diff line change @@ -144,6 +144,17 @@ trait ImportSuggestions:
144
144
val timer = new Timer ()
145
145
val deadLine = System .currentTimeMillis() + suggestImplicitTimeOut
146
146
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
+
147
158
/** Test whether the head of a given instance matches the expected type `pt`,
148
159
* ignoring any dependent implicit arguments.
149
160
*/
@@ -221,7 +232,9 @@ trait ImportSuggestions:
221
232
Nil
222
233
223
234
roots
224
- .flatMap(_.implicitMembers.filter(shallowTest))
235
+ .flatMap(_.implicitMembers.filter { ref =>
236
+ ! alreadyAvailableCandidates(ref.symbol) && shallowTest(ref)
237
+ })
225
238
// filter whether the head of the implicit can match
226
239
.partition(deepTest)
227
240
// partition into full matches and head matches
Original file line number Diff line number Diff line change 1
1
-- Error: tests/neg/missing-implicit3.scala:3:37 -----------------------------------------------------------------------
2
2
3 |val sortedFoos = List(new Foo).sorted // error
3
3
| ^
4
- | No implicit Ordering defined for B
4
+ | No implicit Ordering defined for B
5
5
|
6
- | where: B is a type variable with constraint >: Foo
7
- | ..
8
- | I found:
6
+ | where: B is a type variable with constraint >: Foo
7
+ | ..
8
+ | I found:
9
9
|
10
- | scala.math.Ordering.ordered [A](/* missing */implicitly[scala.math.Ordering.AsComparable [B]])
10
+ | scala.math.Ordering.comparatorToOrdering [A](/* missing */implicitly[java.util.Comparator [B]])
11
11
|
12
- | But no implicit values were found that match type scala.math.Ordering.AsComparable[B].
13
- |
14
- | One of the following imports might make progress towards fixing the problem:
15
- |
16
- | import math.Ordering.comparatorToOrdering
17
- | import math.Ordering.ordered
18
- |
12
+ | But no implicit values were found that match type java.util.Comparator[B].
You can’t perform that action at this time.
0 commit comments