Skip to content

Commit 4b00d36

Browse files
authored
Merge pull request #9975 from dotty-staging/fix-#9972
Fix #9972: Add missing span on implicit search failures
2 parents b22331e + 8acd032 commit 4b00d36

File tree

6 files changed

+34
-7
lines changed

6 files changed

+34
-7
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -409,13 +409,13 @@ object Implicits:
409409
}
410410

411411
object SearchFailure {
412-
def apply(tpe: SearchFailureType)(using Context): SearchFailure = {
412+
def apply(tpe: SearchFailureType, span: Span)(using Context): SearchFailure = {
413413
val id = tpe match
414414
case tpe: AmbiguousImplicits =>
415415
untpd.SearchFailureIdent(nme.AMBIGUOUS, s"/* ambiguous: ${tpe.explanation} */")
416416
case _ =>
417417
untpd.SearchFailureIdent(nme.MISSING, "/* missing */")
418-
SearchFailure(id.withTypeUnchecked(tpe))
418+
SearchFailure(id.withTypeUnchecked(tpe).withSpan(span))
419419
}
420420
}
421421

@@ -483,7 +483,7 @@ object Implicits:
483483
@sharable object NoMatchingImplicits extends NoMatchingImplicits(NoType, EmptyTree, OrderingConstraint.empty)
484484

485485
@sharable val NoMatchingImplicitsFailure: SearchFailure =
486-
SearchFailure(NoMatchingImplicits)(using NoContext)
486+
SearchFailure(NoMatchingImplicits, NoSpan)(using NoContext)
487487

488488
/** An ambiguous implicits failure */
489489
class AmbiguousImplicits(val alt1: SearchSuccess, val alt2: SearchSuccess, val expectedType: Type, val argument: Tree) extends SearchFailureType {
@@ -1022,7 +1022,7 @@ trait Implicits:
10221022
}
10231023
else result
10241024
case NoMatchingImplicitsFailure =>
1025-
SearchFailure(new NoMatchingImplicits(pt, argument, ctx.typerState.constraint))
1025+
SearchFailure(new NoMatchingImplicits(pt, argument, ctx.typerState.constraint), span)
10261026
case _ =>
10271027
result0
10281028
}
@@ -1123,7 +1123,7 @@ trait Implicits:
11231123
*/
11241124
def tryImplicit(cand: Candidate, contextual: Boolean): SearchResult =
11251125
if checkDivergence(cand) then
1126-
SearchFailure(new DivergingImplicit(cand.ref, wideProto, argument))
1126+
SearchFailure(new DivergingImplicit(cand.ref, wideProto, argument), span)
11271127
else {
11281128
val history = ctx.searchHistory.nest(cand, pt)
11291129
val result =
@@ -1174,7 +1174,7 @@ trait Implicits:
11741174

11751175
if diff < 0 then alt2
11761176
else if diff > 0 then alt1
1177-
else SearchFailure(new AmbiguousImplicits(alt1, alt2, pt, argument))
1177+
else SearchFailure(new AmbiguousImplicits(alt1, alt2, pt, argument), span)
11781178
case _: SearchFailure => alt2
11791179

11801180
/** Try to find a best matching implicit term among all the candidates in `pending`.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ object ProtoTypes {
132132

133133
// equals comes from case class; no need to redefine
134134
end IgnoredProto
135-
135+
136136
final class CachedIgnoredProto(ignored: Type) extends IgnoredProto(ignored)
137137

138138
object IgnoredProto:

tests/neg-macros/i9972/Macro_1.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package notmacro
2+
3+
import scala.util.Not
4+
5+
object Main extends App {
6+
summon[Not[T[Int]]] // error
7+
}

tests/neg-macros/i9972/Test_2.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package notmacro
2+
3+
import scala.quoted._
4+
5+
case class T[A <: AnyKind](s: String)
6+
7+
object T {
8+
implicit inline def derived[A <: AnyKind]: T[A] = ${ reprImpl[A] }
9+
10+
def reprImpl[A <: AnyKind](using t: Type[A])(using ctx: QuoteContext): Expr[T[A]] =
11+
'{ T[A]("") }
12+
}

tests/neg-macros/i9972b/Macro_1.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
def test: Unit =
3+
summon[scala.util.Not[T[Int]]] // error

tests/neg-macros/i9972b/Test_2.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
class T[A]
3+
4+
object T:
5+
implicit inline def derived[A]: T[A] = new T[A]

0 commit comments

Comments
 (0)