Skip to content

Commit 16e21d9

Browse files
committed
Bring back inline traces in error messages
I believe these were lost when we changed to the new SourcePos scheme. At least nobody was setting the `outer` part of a SourcePosition anymore. We now do this at the latest possible stage, when generating MessageContainers in Reporter.
1 parent 59054b0 commit 16e21d9

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

compiler/src/dotty/tools/dotc/reporting/Reporter.scala

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import core.Mode
1313
import dotty.tools.dotc.core.Symbols.{Symbol, NoSymbol}
1414
import diagnostic.messages._
1515
import diagnostic._
16+
import ast.{tpd, Trees}
1617
import Message._
1718

1819
object Reporter {
@@ -89,21 +90,25 @@ trait Reporting { this: Context =>
8990
}
9091

9192
def warning(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit =
92-
reportWarning(new Warning(msg, pos))
93+
reportWarning(new Warning(msg, addInlineds(pos)))
9394

94-
def strictWarning(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit =
95-
if (this.settings.strict.value) error(msg, pos)
96-
else reportWarning(new ExtendMessage(() => msg)(_ + "\n(This would be an error under strict mode)").warning(pos))
95+
def strictWarning(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit = {
96+
val fullPos = addInlineds(pos)
97+
if (this.settings.strict.value) error(msg, fullPos)
98+
else reportWarning(new ExtendMessage(() => msg)(_ + "\n(This would be an error under strict mode)").warning(fullPos))
99+
}
97100

98101
def error(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit =
99-
reporter.report(new Error(msg, pos))
102+
reporter.report(new Error(msg, addInlineds(pos)))
100103

101-
def errorOrMigrationWarning(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit =
102-
if (ctx.scala2Mode) migrationWarning(msg, pos) else error(msg, pos)
104+
def errorOrMigrationWarning(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit = {
105+
val fullPos = addInlineds(pos)
106+
if (ctx.scala2Mode) migrationWarning(msg, fullPos) else error(msg, fullPos)
107+
}
103108

104109
def restrictionError(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit =
105110
reporter.report {
106-
new ExtendMessage(() => msg)(m => s"Implementation restriction: $m").error(pos)
111+
new ExtendMessage(() => msg)(m => s"Implementation restriction: $m").error(addInlineds(pos))
107112
}
108113

109114
def incompleteInputError(msg: => Message, pos: SourcePosition = NoSourcePosition)(implicit ctx: Context): Unit =
@@ -135,6 +140,14 @@ trait Reporting { this: Context =>
135140

136141
def debugwarn(msg: => String, pos: SourcePosition = NoSourcePosition): Unit =
137142
if (this.settings.Ydebug.value) warning(msg, pos)
143+
144+
private def addInlineds(pos: SourcePosition)(implicit ctx: Context) = {
145+
def recur(pos: SourcePosition, inlineds: List[Trees.Tree[_]]): SourcePosition = inlineds match {
146+
case inlined :: inlineds1 => pos.withOuter(recur(inlined.sourcePos, inlineds1))
147+
case Nil => pos
148+
}
149+
recur(pos, tpd.enclosingInlineds)
150+
}
138151
}
139152

140153
/**

0 commit comments

Comments
 (0)