diff --git a/compiler/src/dotty/tools/dotc/typer/Inliner.scala b/compiler/src/dotty/tools/dotc/typer/Inliner.scala index 4895da94c56c..d5d49bedb14b 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inliner.scala @@ -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 _ => diff --git a/compiler/test/dotc/run-test-pickling.blacklist b/compiler/test/dotc/run-test-pickling.blacklist index 873c34a19c42..aa76a78cf413 100644 --- a/compiler/test/dotc/run-test-pickling.blacklist +++ b/compiler/test/dotc/run-test-pickling.blacklist @@ -36,4 +36,5 @@ zero-arity-case-class.scala i12194.scala i12753 t6138 -t6138-2 \ No newline at end of file +t6138-2 +i12656.scala diff --git a/tests/run/i12656.scala b/tests/run/i12656.scala new file mode 100644 index 000000000000..ee22988ac771 --- /dev/null +++ b/tests/run/i12656.scala @@ -0,0 +1,16 @@ +transparent inline def expectCompileError( + inline code: String, + expectedMsg: String +) = + val errors = compiletime.testing.typeCheckErrors(code) + assert(errors.head.message == expectedMsg, (errors.head.message, expectedMsg)) + +transparent inline def expectTypeCheck( + inline code: String, +) : Boolean = compiletime.testing.typeChecks(code) + +@main def Test = + assert(!expectTypeCheck("""compiletime.error("some error")""")) + assert(expectTypeCheck("""1 + 1""")) + expectCompileError("""compiletime.error("some error")""", "some error") +