Skip to content

Commit f80848f

Browse files
authored
Merge pull request #14530 from dotty-staging/backport-#14405
Set context when reporting summonInline errors
2 parents cbe27ae + f15746a commit f80848f

File tree

3 files changed

+34
-18
lines changed

3 files changed

+34
-18
lines changed

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

+22-18
Original file line numberDiff line numberDiff line change
@@ -849,13 +849,15 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
849849
def searchImplicit(tpt: Tree) =
850850
val evTyper = new Typer(ctx.nestingLevel + 1)
851851
val evCtx = ctx.fresh.setTyper(evTyper)
852-
val evidence = evTyper.inferImplicitArg(tpt.tpe, tpt.span)(using evCtx)
853-
evidence.tpe match
854-
case fail: Implicits.SearchFailureType =>
855-
val msg = evTyper.missingArgMsg(evidence, tpt.tpe, "")
856-
errorTree(tpt, em"$msg")
857-
case _ =>
858-
evidence
852+
inContext(evCtx) {
853+
val evidence = evTyper.inferImplicitArg(tpt.tpe, tpt.span)
854+
evidence.tpe match
855+
case fail: Implicits.SearchFailureType =>
856+
val msg = evTyper.missingArgMsg(evidence, tpt.tpe, "")
857+
errorTree(call, em"$msg")
858+
case _ =>
859+
evidence
860+
}
859861
return searchImplicit(callTypeArgs.head)
860862
}
861863

@@ -1318,17 +1320,19 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
13181320
def searchImplicit(sym: TermSymbol, tpt: Tree) = {
13191321
val evTyper = new Typer(ctx.nestingLevel + 1)
13201322
val evCtx = ctx.fresh.setTyper(evTyper)
1321-
val evidence = evTyper.inferImplicitArg(tpt.tpe, tpt.span)(using evCtx)
1322-
evidence.tpe match {
1323-
case fail: Implicits.AmbiguousImplicits =>
1324-
report.error(evTyper.missingArgMsg(evidence, tpt.tpe, ""), tpt.srcPos)
1325-
true // hard error: return true to stop implicit search here
1326-
case fail: Implicits.SearchFailureType =>
1327-
false
1328-
case _ =>
1329-
//inlining.println(i"inferred implicit $sym: ${sym.info} with $evidence: ${evidence.tpe.widen}, ${evCtx.gadt.constraint}, ${evCtx.typerState.constraint}")
1330-
newTermBinding(sym, evidence)
1331-
true
1323+
inContext(evCtx) {
1324+
val evidence = evTyper.inferImplicitArg(tpt.tpe, tpt.span)
1325+
evidence.tpe match {
1326+
case fail: Implicits.AmbiguousImplicits =>
1327+
report.error(evTyper.missingArgMsg(evidence, tpt.tpe, ""), tpt.srcPos)
1328+
true // hard error: return true to stop implicit search here
1329+
case fail: Implicits.SearchFailureType =>
1330+
false
1331+
case _ =>
1332+
//inlining.println(i"inferred implicit $sym: ${sym.info} with $evidence: ${evidence.tpe.widen}, ${evCtx.gadt.constraint}, ${evCtx.typerState.constraint}")
1333+
newTermBinding(sym, evidence)
1334+
true
1335+
}
13321336
}
13331337
}
13341338

tests/neg-macros/i13406/Qux_1.scala

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Qux_1.scala
2+
sealed trait Qux[T] // anonymous mirror because no companion
3+
object QuxImpl:
4+
case class Foo[A](a: A) extends Qux[A]

tests/neg-macros/i13406/Test_2.scala

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Test_2.scala
2+
trait Bar
3+
4+
inline given derivedReducible(using scala.deriving.Mirror.SumOf[Qux[_]]): Bar =
5+
scala.compiletime.summonInline[Bar]
6+
???
7+
8+
def test = derivedReducible // error

0 commit comments

Comments
 (0)