Skip to content

Commit cb3a4ef

Browse files
andrzejresselnicolasstucki
authored andcommitted
Set context when reporting summonInline errors
Backport of #14405
1 parent 2ace654 commit cb3a4ef

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

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

+9-7
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

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)