Skip to content

Fix compiler crash when file path is invalid #9147

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

Merged
merged 2 commits into from
Jun 9, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/Run.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
8 changes: 7 additions & 1 deletion compiler/src/dotty/tools/dotc/core/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -248,11 +249,16 @@ object Contexts {
def getSource(path: TermName): SourceFile = base.sourceNamed.get(path) match {
case Some(source) =>
source
case None =>
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 */
Expand Down