aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Martres <smarter@ubuntu.com>2016-02-03 22:42:36 +0100
committerGuillaume Martres <smarter@ubuntu.com>2016-02-04 23:21:58 +0100
commit73fad44a11dafa507e1d358f1bc222b04319a594 (patch)
treef19126df90f4d76235515c56412997343030065a
parentf926c8c14a7b48f2c0f3da680c69881ddfb9bf46 (diff)
downloaddotty-73fad44a11dafa507e1d358f1bc222b04319a594.tar.gz
dotty-73fad44a11dafa507e1d358f1bc222b04319a594.tar.bz2
dotty-73fad44a11dafa507e1d358f1bc222b04319a594.zip
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.
-rw-r--r--src/dotty/tools/dotc/Driver.scala10
-rw-r--r--test/dotty/partest/DPDirectCompiler.scala6
-rw-r--r--test/test/CompilerTest.scala4
3 files changed, 8 insertions, 12 deletions
diff --git a/src/dotty/tools/dotc/Driver.scala b/src/dotty/tools/dotc/Driver.scala
index 1627b6e48..57fa4a052 100644
--- a/src/dotty/tools/dotc/Driver.scala
+++ b/src/dotty/tools/dotc/Driver.scala
@@ -33,12 +33,10 @@ abstract class Driver extends DotClass {
protected def sourcesRequired = true
def setup(args: Array[String], rootCtx: Context): (List[String], Context) = {
- val summary = CompilerCommand.distill(args)(rootCtx)
- // FIXME: We should reuse rootCtx instead of creating newCtx, but this
- // makes some tests fail with "denotation module _root_ invalid in run 2."
- val newCtx = initCtx.setCompilerCallback(rootCtx.compilerCallback)
- implicit val ctx: Context = newCtx.fresh.setSettings(summary.sstate)
- val fileNames = CompilerCommand.checkUsage(summary, sourcesRequired)
+ val ctx = rootCtx.fresh
+ val summary = CompilerCommand.distill(args)(ctx)
+ ctx.setSettings(summary.sstate)
+ val fileNames = CompilerCommand.checkUsage(summary, sourcesRequired)(ctx)
(fileNames, ctx)
}
diff --git a/test/dotty/partest/DPDirectCompiler.scala b/test/dotty/partest/DPDirectCompiler.scala
index a6f11ec64..4e563820f 100644
--- a/test/dotty/partest/DPDirectCompiler.scala
+++ b/test/dotty/partest/DPDirectCompiler.scala
@@ -5,7 +5,7 @@ import scala.tools.partest.{ TestState, nest }
import java.io.{ File, PrintWriter, FileWriter }
-/* NOTE: Adapted from partest.DirectCompiler and DottyTest */
+/* NOTE: Adapted from partest.DirectCompiler */
class DPDirectCompiler(runner: DPTestRunner) extends nest.DirectCompiler(runner) {
override def compile(opts0: List[String], sources: List[File]): TestState = {
@@ -15,9 +15,7 @@ class DPDirectCompiler(runner: DPTestRunner) extends nest.DirectCompiler(runner)
implicit val ctx: dotty.tools.dotc.core.Contexts.Context = {
val base = new dotty.tools.dotc.core.Contexts.ContextBase
- val ctx = base.initialCtx.fresh
- base.definitions.init(ctx)
- ctx
+ base.initialCtx.fresh
}
try {
diff --git a/test/test/CompilerTest.scala b/test/test/CompilerTest.scala
index c65710e7d..526392576 100644
--- a/test/test/CompilerTest.scala
+++ b/test/test/CompilerTest.scala
@@ -33,7 +33,7 @@ import org.junit.Test
* object Test { def main(args: Array[String]): Unit = ... }
* Classpath jars can be added to partestDeps in the sbt Build.scala.
*/
-abstract class CompilerTest extends DottyTest {
+abstract class CompilerTest {
/** Override with output dir of test so it can be patched. Partest expects
* classes to be in partest-generated/[kind]/[testname]-[kind].obj/ */
@@ -181,7 +181,7 @@ abstract class CompilerTest extends DottyTest {
private def compileArgs(args: Array[String], xerrors: Int = 0)(implicit defaultOptions: List[String]): Unit = {
val allArgs = args ++ defaultOptions
val processor = if (allArgs.exists(_.startsWith("#"))) Bench else Main
- val nerrors = processor.process(allArgs, ctx).errorCount
+ val nerrors = processor.process(allArgs).errorCount
assert(nerrors == xerrors, s"Wrong # of errors. Expected: $xerrors, found: $nerrors")
}