Skip to content

Fix #9972: Add missing span on implicit search failures #9975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -409,13 +409,13 @@ object Implicits:
}

object SearchFailure {
def apply(tpe: SearchFailureType)(using Context): SearchFailure = {
def apply(tpe: SearchFailureType, span: Span)(using Context): SearchFailure = {
val id = tpe match
case tpe: AmbiguousImplicits =>
untpd.SearchFailureIdent(nme.AMBIGUOUS, s"/* ambiguous: ${tpe.explanation} */")
case _ =>
untpd.SearchFailureIdent(nme.MISSING, "/* missing */")
SearchFailure(id.withTypeUnchecked(tpe))
SearchFailure(id.withTypeUnchecked(tpe).withSpan(span))
}
}

Expand Down Expand Up @@ -483,7 +483,7 @@ object Implicits:
@sharable object NoMatchingImplicits extends NoMatchingImplicits(NoType, EmptyTree, OrderingConstraint.empty)

@sharable val NoMatchingImplicitsFailure: SearchFailure =
SearchFailure(NoMatchingImplicits)(using NoContext)
SearchFailure(NoMatchingImplicits, NoSpan)(using NoContext)

/** An ambiguous implicits failure */
class AmbiguousImplicits(val alt1: SearchSuccess, val alt2: SearchSuccess, val expectedType: Type, val argument: Tree) extends SearchFailureType {
Expand Down Expand Up @@ -1022,7 +1022,7 @@ trait Implicits:
}
else result
case NoMatchingImplicitsFailure =>
SearchFailure(new NoMatchingImplicits(pt, argument, ctx.typerState.constraint))
SearchFailure(new NoMatchingImplicits(pt, argument, ctx.typerState.constraint), span)
case _ =>
result0
}
Expand Down Expand Up @@ -1123,7 +1123,7 @@ trait Implicits:
*/
def tryImplicit(cand: Candidate, contextual: Boolean): SearchResult =
if checkDivergence(cand) then
SearchFailure(new DivergingImplicit(cand.ref, wideProto, argument))
SearchFailure(new DivergingImplicit(cand.ref, wideProto, argument), span)
else {
val history = ctx.searchHistory.nest(cand, pt)
val result =
Expand Down Expand Up @@ -1174,7 +1174,7 @@ trait Implicits:

if diff < 0 then alt2
else if diff > 0 then alt1
else SearchFailure(new AmbiguousImplicits(alt1, alt2, pt, argument))
else SearchFailure(new AmbiguousImplicits(alt1, alt2, pt, argument), span)
case _: SearchFailure => alt2

/** Try to find a best matching implicit term among all the candidates in `pending`.
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ object ProtoTypes {

// equals comes from case class; no need to redefine
end IgnoredProto

final class CachedIgnoredProto(ignored: Type) extends IgnoredProto(ignored)

object IgnoredProto:
Expand Down
7 changes: 7 additions & 0 deletions tests/neg-macros/i9972/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package notmacro

import scala.util.Not

object Main extends App {
summon[Not[T[Int]]] // error
}
12 changes: 12 additions & 0 deletions tests/neg-macros/i9972/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package notmacro

import scala.quoted._

case class T[A <: AnyKind](s: String)

object T {
implicit inline def derived[A <: AnyKind]: T[A] = ${ reprImpl[A] }

def reprImpl[A <: AnyKind](using t: Type[A])(using ctx: QuoteContext): Expr[T[A]] =
'{ T[A]("") }
}
3 changes: 3 additions & 0 deletions tests/neg-macros/i9972b/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

def test: Unit =
summon[scala.util.Not[T[Int]]] // error
5 changes: 5 additions & 0 deletions tests/neg-macros/i9972b/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

class T[A]

object T:
implicit inline def derived[A]: T[A] = new T[A]