From 7e85b595502974bebf2f2625c6bc3645f0d3ab27 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Tue, 17 Dec 2013 17:47:15 +0100 Subject: SI-8085 Fix BrowserTraverser for package objects A source file like: import foo.bar package object baz Is parsed into: package { import foo.bar package baz { object `package` } } A special case in Namers compensates by adjusting the owner of `baz` to be ``, rather than ``. This wasn't being accounted for in `BrowserTraverser`, which underpins `-sourcepath`, and allows the presentation compiler to load top level symbols from sources outside those passes as the list of sources to compile. This bug did not appear in sources like: package p1 package object p2 { ... } ... because the parser does not wrap this in the `package {}` This goes some way to explaining why it has gone unnoticed for so long. --- test/files/presentation/t8085b/Test.scala | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 test/files/presentation/t8085b/Test.scala (limited to 'test/files/presentation/t8085b/Test.scala') diff --git a/test/files/presentation/t8085b/Test.scala b/test/files/presentation/t8085b/Test.scala new file mode 100644 index 0000000000..e46b7ab8c8 --- /dev/null +++ b/test/files/presentation/t8085b/Test.scala @@ -0,0 +1,27 @@ +import scala.tools.nsc.interactive.tests.InteractiveTest +import scala.reflect.internal.util.SourceFile +import scala.tools.nsc.interactive.Response + +object Test extends InteractiveTest { + + override def execute(): Unit = { + val src = loadSourceAndWaitUntilTypechecked("NodeScalaSuite.scala") + checkErrors(src) + } + + private def loadSourceAndWaitUntilTypechecked(sourceName: String): SourceFile = { + val sourceFile = sourceFiles.find(_.file.name == sourceName).head + askReload(List(sourceFile)).get + askLoadedTyped(sourceFile).get + sourceFile + } + + private def checkErrors(source: SourceFile): Unit = compiler.getUnitOf(source) match { + case Some(unit) => + val problems = unit.problems.toList + if(problems.isEmpty) reporter.println("Test OK") + else problems.foreach(problem => reporter.println(problem.msg)) + + case None => reporter.println("No compilation unit found for " + source.file.name) + } +} -- cgit v1.2.3