Skip to content

Commit 3a849fc

Browse files
committed
Compile an empty source in InteractiveDriver ctor
This is necessary because we may be using this InteractiveDriver before asking it to compile anything (which would have initialized it). This happens, for instance, if we use this Driver to resolve a symbol coming from a different Driver. Drivers are not meant to be used before being initialized and can crash.
1 parent 5cce774 commit 3a849fc

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

compiler/src/dotty/tools/dotc/interactive/InteractiveDriver.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ class InteractiveDriver(val settings: List[String]) extends Driver {
8686
names
8787
}
8888

89+
initialize()
90+
8991
/**
9092
* The trees for all the source files in this project.
9193
*
@@ -298,6 +300,18 @@ class InteractiveDriver(val settings: List[String]) extends Driver {
298300
new SourceFile(virtualFile, Codec.UTF8)
299301
}
300302

303+
/**
304+
* Initialize this driver and compiler by "compiling" a fake, empty source file.
305+
*
306+
* This is necessary because an `InteractiveDriver` can be put to work without having
307+
* compiled anything (for instance, resolving a symbol coming from a different compiler in
308+
* this compiler). In those cases, an un-initialized compiler will crash.
309+
*/
310+
private[this] def initialize(): Unit = {
311+
val fakeSource = new File("fake.scala")
312+
run(fakeSource.toURI, "")
313+
}
314+
301315
}
302316

303317
object InteractiveDriver {

0 commit comments

Comments
 (0)