Skip to content

Commit 73fad44

Browse files
committed
Driver: properly use root Context passed as argument
Also CompilerTest no longer runs the compiler with the context DottyTest#ctx. Previously, we got away with this because Compiler#process ignored it and created a new Context, but this commit fixes this, and it is now very important that we use a different context for every test we compile. Since DottyTest#ctx was the only part of DottyTest we used, CompilerTest no longer extends DottyTest to make sure that we do not use it accidentally. If we want to use DottyTest as a base class for tests again, we will have to remove its implicit Context field first. Also do not try to initialize the definitions in the context used by partest, this is not necessary.
1 parent f926c8c commit 73fad44

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

src/dotty/tools/dotc/Driver.scala

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,10 @@ abstract class Driver extends DotClass {
3333
protected def sourcesRequired = true
3434

3535
def setup(args: Array[String], rootCtx: Context): (List[String], Context) = {
36-
val summary = CompilerCommand.distill(args)(rootCtx)
37-
// FIXME: We should reuse rootCtx instead of creating newCtx, but this
38-
// makes some tests fail with "denotation module _root_ invalid in run 2."
39-
val newCtx = initCtx.setCompilerCallback(rootCtx.compilerCallback)
40-
implicit val ctx: Context = newCtx.fresh.setSettings(summary.sstate)
41-
val fileNames = CompilerCommand.checkUsage(summary, sourcesRequired)
36+
val ctx = rootCtx.fresh
37+
val summary = CompilerCommand.distill(args)(ctx)
38+
ctx.setSettings(summary.sstate)
39+
val fileNames = CompilerCommand.checkUsage(summary, sourcesRequired)(ctx)
4240
(fileNames, ctx)
4341
}
4442

test/dotty/partest/DPDirectCompiler.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import scala.tools.partest.{ TestState, nest }
55
import java.io.{ File, PrintWriter, FileWriter }
66

77

8-
/* NOTE: Adapted from partest.DirectCompiler and DottyTest */
8+
/* NOTE: Adapted from partest.DirectCompiler */
99
class DPDirectCompiler(runner: DPTestRunner) extends nest.DirectCompiler(runner) {
1010

1111
override def compile(opts0: List[String], sources: List[File]): TestState = {
@@ -15,9 +15,7 @@ class DPDirectCompiler(runner: DPTestRunner) extends nest.DirectCompiler(runner)
1515

1616
implicit val ctx: dotty.tools.dotc.core.Contexts.Context = {
1717
val base = new dotty.tools.dotc.core.Contexts.ContextBase
18-
val ctx = base.initialCtx.fresh
19-
base.definitions.init(ctx)
20-
ctx
18+
base.initialCtx.fresh
2119
}
2220

2321
try {

test/test/CompilerTest.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import org.junit.Test
3333
* object Test { def main(args: Array[String]): Unit = ... }
3434
* Classpath jars can be added to partestDeps in the sbt Build.scala.
3535
*/
36-
abstract class CompilerTest extends DottyTest {
36+
abstract class CompilerTest {
3737

3838
/** Override with output dir of test so it can be patched. Partest expects
3939
* classes to be in partest-generated/[kind]/[testname]-[kind].obj/ */
@@ -181,7 +181,7 @@ abstract class CompilerTest extends DottyTest {
181181
private def compileArgs(args: Array[String], xerrors: Int = 0)(implicit defaultOptions: List[String]): Unit = {
182182
val allArgs = args ++ defaultOptions
183183
val processor = if (allArgs.exists(_.startsWith("#"))) Bench else Main
184-
val nerrors = processor.process(allArgs, ctx).errorCount
184+
val nerrors = processor.process(allArgs).errorCount
185185
assert(nerrors == xerrors, s"Wrong # of errors. Expected: $xerrors, found: $nerrors")
186186
}
187187

0 commit comments

Comments
 (0)