Skip to content

Commit 8324d4b

Browse files
committed
Bring back explanations of implicit searches for extensions
Bring back explanations if an implicit search was tried to resolve an extension method.
1 parent d4e6c77 commit 8324d4b

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,20 +141,26 @@ object ErrorReporting {
141141
if Feature.migrateTo3 then "\nThis patch can be inserted automatically under -rewrite."
142142
else ""
143143

144+
def whyFailedStr(fail: FailedExtension) =
145+
i""" failed with
146+
|
147+
|${fail.whyFailed.message.indented(8)}"""
148+
144149
def selectErrorAddendum
145150
(tree: untpd.RefTree, qual1: Tree, qualType: Type, suggestImports: Type => String)
146151
(using Context): String =
147152

148-
val attempts = mutable.ListBuffer[(Tree, FailedExtension)]()
153+
val attempts = mutable.ListBuffer[(Tree, String)]()
149154
val nested = mutable.ListBuffer[NestedFailure]()
150155
for
151156
failures <- qual1.getAttachment(Typer.HiddenSearchFailure)
152157
failure <- failures
153158
do
154159
failure.reason match
155160
case fail: NestedFailure => nested += fail
156-
case fail: FailedExtension => attempts += ((failure.tree, fail))
157-
case _ =>
161+
case fail: FailedExtension => attempts += ((failure.tree, whyFailedStr(fail)))
162+
case fail: Implicits.NoMatchingImplicits => // do nothing
163+
case _ => attempts += ((failure.tree, ""))
158164
if qualType.derivesFrom(defn.DynamicClass) then
159165
"\npossible cause: maybe a wrong Dynamic method signature?"
160166
else if attempts.nonEmpty then
@@ -164,9 +170,7 @@ object ErrorReporting {
164170
.distinctBy(_._1)
165171
.map((treeStr, whyFailed) =>
166172
i"""
167-
| $treeStr failed with
168-
|
169-
|${whyFailed.whyFailed.message.indented(8)}""")
173+
| $treeStr$whyFailed""")
170174
val extMethods =
171175
if attemptStrings.length > 1 then "Extension methods were"
172176
else "An extension method was"

tests/neg/i7056.check

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- [E008] Not Found Error: tests/neg/i7056.scala:19:10 -----------------------------------------------------------------
2+
19 |val z = x.idnt1 // error
3+
| ^^^^^^^
4+
| value idnt1 is not a member of B.
5+
| An extension method was tried, but could not be fully constructed:
6+
|
7+
| i7056$package.given_T1_T[T](given_PartialId_B).idnt1()

tests/neg/i7056.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
type A
2+
type B <: A
3+
4+
type PartialId[X] = X match {
5+
case B => X
6+
}
7+
8+
trait T1[T] {
9+
extension (t1: T) def idnt1: Any
10+
}
11+
12+
given [T <: A](using PartialId[T]): T1[T] = new T1[T] {
13+
extension (t1: T) def idnt1: Any = ???
14+
}
15+
16+
given PartialId[B] = ???
17+
18+
val x: B = ???
19+
val z = x.idnt1 // error

0 commit comments

Comments
 (0)