From 59862cfff4c9bf95c62651cdcdf19d5033a8febf Mon Sep 17 00:00:00 2001 From: noti0na1 Date: Tue, 9 Jun 2020 18:57:01 +0200 Subject: [PATCH 1/2] fix crash when file path is invalid --- compiler/src/dotty/tools/dotc/Run.scala | 3 ++- compiler/src/dotty/tools/dotc/core/Contexts.scala | 14 +++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/Run.scala b/compiler/src/dotty/tools/dotc/Run.scala index 747b719cb881..1a723a79204c 100644 --- a/compiler/src/dotty/tools/dotc/Run.scala +++ b/compiler/src/dotty/tools/dotc/Run.scala @@ -111,7 +111,8 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint } catch { case NonFatal(ex) => - runContext.echo(i"exception occurred while compiling $units%, %") + if units != null then runContext.echo(i"exception occurred while compiling $units%, %") + else runContext.echo(s"exception occurred while compiling ${fileNames.mkString(", ")}") throw ex } diff --git a/compiler/src/dotty/tools/dotc/core/Contexts.scala b/compiler/src/dotty/tools/dotc/core/Contexts.scala index b54f6d320693..777c83a73b6f 100644 --- a/compiler/src/dotty/tools/dotc/core/Contexts.scala +++ b/compiler/src/dotty/tools/dotc/core/Contexts.scala @@ -36,6 +36,7 @@ import util.Store import xsbti.AnalysisCallback import plugins._ import java.util.concurrent.atomic.AtomicInteger +import java.nio.file.InvalidPathException object Contexts { @@ -249,9 +250,16 @@ object Contexts { case Some(source) => source case None => - val f = new PlainFile(Path(path.toString)) - val src = getSource(f) - base.sourceNamed(path) = src + val src = try { + val f = new PlainFile(Path(path.toString)) + val s = getSource(f) + base.sourceNamed(path) = s + s + } catch { + case ex: InvalidPathException => + ctx.error(s"invalid file path: ${ex.getMessage}") + NoSource + } src } From f68ae17a4ab44cf634aaf47b6c745528d8fc433e Mon Sep 17 00:00:00 2001 From: noti0na1 Date: Tue, 9 Jun 2020 19:00:06 +0200 Subject: [PATCH 2/2] simplify --- .../src/dotty/tools/dotc/core/Contexts.scala | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/Contexts.scala b/compiler/src/dotty/tools/dotc/core/Contexts.scala index 777c83a73b6f..232a893072ff 100644 --- a/compiler/src/dotty/tools/dotc/core/Contexts.scala +++ b/compiler/src/dotty/tools/dotc/core/Contexts.scala @@ -249,18 +249,16 @@ object Contexts { def getSource(path: TermName): SourceFile = base.sourceNamed.get(path) match { case Some(source) => source - case None => - val src = try { - val f = new PlainFile(Path(path.toString)) - val s = getSource(f) - base.sourceNamed(path) = s - s - } catch { - case ex: InvalidPathException => - ctx.error(s"invalid file path: ${ex.getMessage}") - NoSource - } + case None => try { + val f = new PlainFile(Path(path.toString)) + val src = getSource(f) + base.sourceNamed(path) = src src + } catch { + case ex: InvalidPathException => + ctx.error(s"invalid file path: ${ex.getMessage}") + NoSource + } } /** Sourcefile with given path, memoized */