Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #12656 by setting the proper reporter for inlined methods #13543

Merged
merged 4 commits into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
3 changes: 2 additions & 1 deletion compiler/test/dotc/run-test-pickling.blacklist
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ zero-arity-case-class.scala
i12194.scala
i12753
t6138
t6138-2
t6138-2
i12656.scala
16 changes: 16 additions & 0 deletions tests/run/i12656.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
transparent inline def expectCompileError(
inline code: String,
expectedMsg: String
) =
val errors = compiletime.testing.typeCheckErrors(code)
soronpo marked this conversation as resolved.
Show resolved Hide resolved
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")