Skip to content

Commit c5aac05

Browse files
Merge pull request scala#13543 from soronpo/fix_i12656
Fix scala#12656 by setting the proper reporter for inlined methods
2 parents dc9e2c7 + 24a5ea5 commit c5aac05

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -972,11 +972,13 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
972972
}
973973
// Usually `error` is called from within a rewrite method. In this
974974
// case we need to report the error at the point of the outermost enclosing inline
975-
// call. This way, a defensively written rewrite methid can always
975+
// call. This way, a defensively written rewrite method can always
976976
// report bad inputs at the point of call instead of revealing its internals.
977977
val callToReport = if (enclosingInlineds.nonEmpty) enclosingInlineds.last else call
978978
val ctxToReport = ctx.outersIterator.dropWhile(enclosingInlineds(using _).nonEmpty).next
979-
inContext(ctxToReport) {
979+
// The context in which we report should still use the existing context reporter
980+
val ctxOrigReporter = ctxToReport.fresh.setReporter(ctx.reporter)
981+
inContext(ctxOrigReporter) {
980982
report.error(message, callToReport.srcPos)
981983
}
982984
case _ =>

compiler/test/dotc/run-test-pickling.blacklist

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@ zero-arity-case-class.scala
3636
i12194.scala
3737
i12753
3838
t6138
39-
t6138-2
39+
t6138-2
40+
i12656.scala

tests/run/i12656.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
transparent inline def expectCompileError(
2+
inline code: String,
3+
expectedMsg: String
4+
) =
5+
val errors = compiletime.testing.typeCheckErrors(code)
6+
assert(errors.head.message == expectedMsg, (errors.head.message, expectedMsg))
7+
8+
transparent inline def expectTypeCheck(
9+
inline code: String,
10+
) : Boolean = compiletime.testing.typeChecks(code)
11+
12+
@main def Test =
13+
assert(!expectTypeCheck("""compiletime.error("some error")"""))
14+
assert(expectTypeCheck("""1 + 1"""))
15+
expectCompileError("""compiletime.error("some error")""", "some error")
16+

0 commit comments

Comments
 (0)