Skip to content

Commit

Permalink
Fix #12656 by setting the proper reporter for inlined methods
Browse files Browse the repository at this point in the history
  • Loading branch information
soronpo committed Sep 16, 2021
1 parent 8d9542c commit 5fde87f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 4 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -972,11 +972,13 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
}
// Usually `error` is called from within a rewrite method. In this
// case we need to report the error at the point of the outermost enclosing inline
// call. This way, a defensively written rewrite methid can always
// call. This way, a defensively written rewrite method can always
// report bad inputs at the point of call instead of revealing its internals.
val callToReport = if (enclosingInlineds.nonEmpty) enclosingInlineds.last else call
val ctxToReport = ctx.outersIterator.dropWhile(enclosingInlineds(using _).nonEmpty).next
inContext(ctxToReport) {
// The context in which we report should still use the existing context reporter
val ctxOrigReporter = ctxToReport.fresh.setReporter(ctx.reporter)
inContext(ctxOrigReporter) {
report.error(message, callToReport.srcPos)
}
case _ =>
Expand Down
8 changes: 8 additions & 0 deletions tests/run/i12656.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
transparent inline def expectCompileError(
inline code: String,
expectedMsg: String
) =
val errors = compiletime.testing.typeCheckErrors(code)
assert(errors.head.message == expectedMsg, (errors.head.message, expectedMsg))

@main def Test = expectCompileError("""compiletime.error("some error")""", "some error")

0 comments on commit 5fde87f

Please sign in to comment.