Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SI-8085 Fix BrowserTraverser for package objects
A source file like: import foo.bar package object baz Is parsed into: package <empty> { import foo.bar package baz { object `package` } } A special case in Namers compensates by adjusting the owner of `baz` to be `<root>`, rather than `<empty>`. 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 <empty> {}` This goes some way to explaining why it has gone unnoticed for so long.
- Loading branch information
Showing
11 changed files
with
66 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
reload: NodeScalaSuite.scala | ||
prefixes differ: <empty>.nodescala,nodescala | ||
value always is not a member of object scala.concurrent.Future | ||
open package module: package nodescala | ||
Test OK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
test/files/presentation/t8085/src/nodescala/NodeScalaSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
package nodescala | ||
|
||
import scala.concurrent.Future | ||
|
||
class NodeScalaSuite { | ||
Future.always(517) | ||
"".rich | ||
|
||
// This is here only to prove that the presentation compiler is instantiated with the | ||
// correct `sourcepath` value (if it wasn't, you would see a `not found: type Foo` in | ||
// the test's output | ||
println(new Foo()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
import scala.concurrent.Future // <-- if you move the import *inside* the package object, then it all works fine!! | ||
import scala.Some // <-- if you move the import *inside* the package object, then it all works fine!! | ||
|
||
package object nodescala { | ||
implicit class FutureCompanionOps[T](val f: Future.type) extends AnyVal { | ||
def always[T](value: T): Future[T] = Promise[T].success(value).future | ||
implicit class StringOps(val f: String) { | ||
def rich = 0 | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
reload: NodeScalaSuite.scala | ||
open package module: package nodescala | ||
Test OK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-sourcepath src |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package p1 | ||
package nodescala | ||
|
||
class Foo |
11 changes: 11 additions & 0 deletions
11
test/files/presentation/t8085b/src/p1/nodescala/NodeScalaSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package p1 | ||
package nodescala | ||
|
||
class NodeScalaSuite { | ||
"".rich | ||
|
||
// This is here only to prove that the presentation compiler is instantiated with the | ||
// correct `sourcepath` value (if it wasn't, you would see a `not found: type Foo` in | ||
// the test's output | ||
println(new Foo()) | ||
} |
9 changes: 9 additions & 0 deletions
9
test/files/presentation/t8085b/src/p1/nodescala/package.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import scala.Some // <-- if you move the import *inside* the package object, then it all works fine!! | ||
|
||
package p1 { | ||
package object nodescala { | ||
implicit class StringOps(val f: String) { | ||
def rich = 0 | ||
} | ||
} | ||
} |