Skip to content

Commit

Permalink
Merge pull request #14405 from andrzejressel/fix_13406
Browse files Browse the repository at this point in the history
Set context when reporting summonInline errors
  • Loading branch information
nicolasstucki committed Feb 21, 2022
2 parents c58f5c5 + 41224fe commit f19b850
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
16 changes: 9 additions & 7 deletions compiler/src/dotty/tools/dotc/typer/Inliner.scala
Expand Up @@ -849,13 +849,15 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
def searchImplicit(tpt: Tree) =
val evTyper = new Typer(ctx.nestingLevel + 1)
val evCtx = ctx.fresh.setTyper(evTyper)
val evidence = evTyper.inferImplicitArg(tpt.tpe, tpt.span)(using evCtx)
evidence.tpe match
case fail: Implicits.SearchFailureType =>
val msg = evTyper.missingArgMsg(evidence, tpt.tpe, "")
errorTree(call, em"$msg")
case _ =>
evidence
inContext(evCtx) {
val evidence = evTyper.inferImplicitArg(tpt.tpe, tpt.span)
evidence.tpe match
case fail: Implicits.SearchFailureType =>
val msg = evTyper.missingArgMsg(evidence, tpt.tpe, "")
errorTree(call, em"$msg")
case _ =>
evidence
}
return searchImplicit(callTypeArgs.head)
}

Expand Down
4 changes: 4 additions & 0 deletions tests/neg-macros/i13406/Qux_1.scala
@@ -0,0 +1,4 @@
// Qux_1.scala
sealed trait Qux[T] // anonymous mirror because no companion
object QuxImpl:
case class Foo[A](a: A) extends Qux[A]
8 changes: 8 additions & 0 deletions tests/neg-macros/i13406/Test_2.scala
@@ -0,0 +1,8 @@
// Test_2.scala
trait Bar

inline given derivedReducible(using scala.deriving.Mirror.SumOf[Qux[_]]): Bar =
scala.compiletime.summonInline[Bar]
???

def test = derivedReducible // error

0 comments on commit f19b850

Please sign in to comment.