Skip to content

Commit defcea3

Browse files
authored
Merge pull request #9147 from noti0na1/fix
Fix compiler crash when file path is invalid
2 parents 74cfd84 + f68ae17 commit defcea3

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
111111
}
112112
catch {
113113
case NonFatal(ex) =>
114-
runContext.echo(i"exception occurred while compiling $units%, %")
114+
if units != null then runContext.echo(i"exception occurred while compiling $units%, %")
115+
else runContext.echo(s"exception occurred while compiling ${fileNames.mkString(", ")}")
115116
throw ex
116117
}
117118

compiler/src/dotty/tools/dotc/core/Contexts.scala

+7-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import util.Store
3636
import xsbti.AnalysisCallback
3737
import plugins._
3838
import java.util.concurrent.atomic.AtomicInteger
39+
import java.nio.file.InvalidPathException
3940

4041
object Contexts {
4142

@@ -248,11 +249,16 @@ object Contexts {
248249
def getSource(path: TermName): SourceFile = base.sourceNamed.get(path) match {
249250
case Some(source) =>
250251
source
251-
case None =>
252+
case None => try {
252253
val f = new PlainFile(Path(path.toString))
253254
val src = getSource(f)
254255
base.sourceNamed(path) = src
255256
src
257+
} catch {
258+
case ex: InvalidPathException =>
259+
ctx.error(s"invalid file path: ${ex.getMessage}")
260+
NoSource
261+
}
256262
}
257263

258264
/** Sourcefile with given path, memoized */

0 commit comments

Comments
 (0)