Skip to content

Commit 9e72e6c

Browse files
committed
Better explanation for missing members that have extension methods
1 parent 02d7594 commit 9e72e6c

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ trait TypeAssigner {
270270
def addendum =
271271
if (qualType.derivesFrom(defn.DynamicClass))
272272
"\npossible cause: maybe a wrong Dynamic method signature?"
273-
else qual1.getAttachment(Typer.HiddenSearchFailure) match {
273+
else qual1.getAttachment(Typer.HiddenSearchFailure) match
274274
case Some(failure) if !failure.reason.isInstanceOf[Implicits.NoMatchingImplicits] =>
275275
i""".
276276
|An extension method was tried, but could not be fully constructed:
@@ -283,10 +283,12 @@ trait TypeAssigner {
283283
|If you do not want that, insert a `;` or empty line in front
284284
|or drop any spaces behind the operator."""
285285
else
286-
implicitSuggestionAddendum(
286+
var add = implicitSuggestionAddendum(
287287
ViewProto(qualType.widen,
288288
SelectionProto(name, WildcardType, NoViewsAllowed, privateOK = false)))
289-
}
289+
if add.isEmpty then ""
290+
else ", but could be made available as an extension method." ++ add
291+
end addendum
290292
errorType(NotAMember(qualType, name, kind, addendum), tree.sourcePos)
291293
}
292294
}

tests/neg/missing-implicit.check

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- [E008] Member Not Found Error: tests/neg/missing-implicit.scala:5:25 ------------------------------------------------
22
5 | case x :: xs1 if limit > 0 => consume(xs1, limit - x) // error // error
33
| ^^^^^^^
4-
| value > is not a member of T
4+
| value > is not a member of T, but could be made available as an extension method.
55
|
66
| One of the following imports might fix the problem:
77
|
@@ -11,12 +11,12 @@
1111
-- [E008] Member Not Found Error: tests/neg/missing-implicit.scala:5:51 ------------------------------------------------
1212
5 | case x :: xs1 if limit > 0 => consume(xs1, limit - x) // error // error
1313
| ^^^^^^^
14-
| value - is not a member of T
14+
| value - is not a member of T, but could be made available as an extension method.
1515
|
16-
| The following import might fix the problem:
16+
| The following import might fix the problem:
1717
|
18-
| import math.Numeric.Implicits.infixNumericOps
19-
|
18+
| import math.Numeric.Implicits.infixNumericOps
19+
|
2020
-- Error: tests/neg/missing-implicit.scala:10:24 -----------------------------------------------------------------------
2121
10 |val f = Future[Unit] { } // error
2222
| ^
@@ -62,11 +62,11 @@
6262
-- [E008] Member Not Found Error: tests/neg/missing-implicit.scala:18:48 -----------------------------------------------
6363
18 |val d2: scala.concurrent.duration.Duration = 10.days // error
6464
| ^^^^^^^
65-
| value days is not a member of Int
65+
| value days is not a member of Int, but could be made available as an extension method.
6666
|
67-
| One of the following imports might fix the problem:
67+
| One of the following imports might fix the problem:
6868
|
69-
| import concurrent.duration.DurationInt
70-
| import concurrent.duration.DurationLong
71-
| import concurrent.duration.DurationDouble
72-
|
69+
| import concurrent.duration.DurationInt
70+
| import concurrent.duration.DurationLong
71+
| import concurrent.duration.DurationDouble
72+
|

tests/neg/missing-implicit1.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
-- [E008] Member Not Found Error: tests/neg/missing-implicit1.scala:16:16 ----------------------------------------------
1111
16 | List(1, 2, 3).traverse(x => Option(x)) // error
1212
| ^^^^^^^^^^^^^^^^^^^^^^
13-
| value traverse is not a member of List[Int] - did you mean List[Int].reverse?
13+
| value traverse is not a member of List[Int], but could be made available as an extension method.
1414
|
1515
| The following import might make progress towards fixing the problem:
1616
|
@@ -37,7 +37,7 @@
3737
-- [E008] Member Not Found Error: tests/neg/missing-implicit1.scala:38:16 ----------------------------------------------
3838
38 | List(1, 2, 3).traverse(x => Option(x)) // error
3939
| ^^^^^^^^^^^^^^^^^^^^^^
40-
| value traverse is not a member of List[Int] - did you mean List[Int].reverse?
40+
| value traverse is not a member of List[Int], but could be made available as an extension method.
4141
|
4242
| The following import might make progress towards fixing the problem:
4343
|

0 commit comments

Comments
 (0)