Skip to content

Commit 5ac8b80

Browse files
committed
Also suggest partial matches for missing implicit arguments
This used to work only for ViewProtos before.
1 parent 427da51 commit 5ac8b80

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,12 @@ trait ImportSuggestions with
146146
*/
147147
def shallowTest(ref: TermRef): Boolean =
148148
System.currentTimeMillis < deadLine
149-
&& (ref <:< pt)(given ctx.fresh.setExploreTyperState())
149+
&& {
150+
given Context = ctx.fresh.setExploreTyperState()
151+
pt match
152+
case pt: ViewProto => pt.isMatchedBy(ref)
153+
case _ => normalize(ref, pt) <:< pt
154+
}
150155

151156
/** Test whether a full given term can be synthesized that matches
152157
* the expected type `pt`.

tests/neg/missing-implicit2.check

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
-- Error: tests/neg/missing-implicit2.scala:10:18 ----------------------------------------------------------------------
2+
10 | f(given xFromY) // error
3+
| ^
4+
| no implicit argument of type Y was found for parameter y of method xFromY
5+
|
6+
| The following import might fix the problem:
7+
|
8+
| import test.instances.y
9+
|
10+
-- Error: tests/neg/missing-implicit2.scala:16:5 -----------------------------------------------------------------------
11+
16 | f // error
12+
| ^
13+
| no implicit argument of type X was found for parameter x of method f in object test
14+
|
15+
| The following import might make progress towards fixing the problem:
16+
|
17+
| import instances2.xFromY
18+
|

tests/neg/missing-implicit2.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
trait X
2+
trait Y
3+
object test with
4+
def f(given x: X) = ???
5+
object instances {
6+
given y: Y = ???
7+
}
8+
locally {
9+
given xFromY(given y: Y): X = ???
10+
f(given xFromY) // error
11+
}
12+
locally {
13+
object instances2 {
14+
given xFromY: Y => X = ???
15+
}
16+
f // error
17+
}

0 commit comments

Comments
 (0)