Skip to content

Commit 099f9f2

Browse files
committed
Unduplicate enrich{,ed}ErrorMessage
Having a same-named enrichement will cause the original to be called if/when explicit nulls is switched off - which leads to the original method to be called, meaning an NPE will be thrown. So, instead, move all the functionality as an extension method, so we don't need mangled names.
1 parent 378f5ff commit 099f9f2

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

compiler/src/dotty/tools/dotc/Run.scala

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -175,19 +175,11 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
175175

176176
private var myEnrichedErrorMessage = false
177177

178-
def enrichedErrorMessage: Boolean = myEnrichedErrorMessage
179-
180-
def enrichErrorMessage(errorMessage: String)(using Context): String =
181-
if enrichedErrorMessage then errorMessage
182-
else
183-
myEnrichedErrorMessage = true
184-
report.enrichErrorMessage(errorMessage)
185-
186178
def compile(files: List[AbstractFile]): Unit =
187179
try compileSources(files.map(runContext.getSource(_)))
188-
catch case NonFatal(ex) if !enrichedErrorMessage =>
180+
catch case NonFatal(ex) if !this.enrichedErrorMessage =>
189181
val files1 = if units.isEmpty then files else units.map(_.source.file)
190-
report.echo(enrichErrorMessage(s"exception occurred while compiling ${files1.map(_.path)}"))
182+
report.echo(this.enrichErrorMessage(s"exception occurred while compiling ${files1.map(_.path)}"))
191183
throw ex
192184

193185
/** TODO: There's a fundamental design problem here: We assemble phases using `fusePhases`
@@ -408,9 +400,13 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
408400

409401
object Run {
410402
extension (run: Run | Null)
411-
def enrichedErrorMessage: Boolean = if run == null then false else run.enrichedErrorMessage
403+
def enrichedErrorMessage: Boolean = if run == null then false else run.myEnrichedErrorMessage
412404
def enrichErrorMessage(errorMessage: String)(using Context): String =
413-
if run == null
414-
then report.enrichErrorMessage(errorMessage)
415-
else run.enrichErrorMessage(errorMessage)
405+
if run == null then
406+
report.enrichErrorMessage(errorMessage)
407+
else if !run.enrichedErrorMessage then
408+
run.myEnrichedErrorMessage = true
409+
report.enrichErrorMessage(errorMessage)
410+
else
411+
errorMessage
416412
}

0 commit comments

Comments
 (0)