Skip to content

Commit 97b9b2c

Browse files
committed
Merge pull request scala#3282 from retronym/ticket/8085
Fix BrowserTraverser for package objects
2 parents 5cbb5a7 + 7e85b59 commit 97b9b2c

File tree

13 files changed

+110
-2
lines changed

13 files changed

+110
-2
lines changed

src/compiler/scala/tools/nsc/symtab/BrowsingLoaders.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ abstract class BrowsingLoaders extends SymbolLoaders {
6464
addPackagePrefix(pre)
6565
packagePrefix += ("." + name)
6666
case Ident(name) =>
67-
if (packagePrefix.length != 0) packagePrefix += "."
68-
packagePrefix += name
67+
if (name != nme.EMPTY_PACKAGE_NAME) { // mirrors logic in Namers, see createPackageSymbol
68+
if (packagePrefix.length != 0) packagePrefix += "."
69+
packagePrefix += name
70+
}
6971
case _ =>
7072
throw new MalformedInput(pkg.pos.point, "illegal tree node in package prefix: "+pkg)
7173
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
reload: NodeScalaSuite.scala
2+
open package module: package nodescala
3+
Test OK
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-sourcepath src
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import scala.tools.nsc.interactive.tests.InteractiveTest
2+
import scala.reflect.internal.util.SourceFile
3+
import scala.tools.nsc.interactive.Response
4+
5+
object Test extends InteractiveTest {
6+
7+
override def execute(): Unit = {
8+
val src = loadSourceAndWaitUntilTypechecked("NodeScalaSuite.scala")
9+
checkErrors(src)
10+
}
11+
12+
private def loadSourceAndWaitUntilTypechecked(sourceName: String): SourceFile = {
13+
val sourceFile = sourceFiles.find(_.file.name == sourceName).head
14+
askReload(List(sourceFile)).get
15+
askLoadedTyped(sourceFile).get
16+
sourceFile
17+
}
18+
19+
private def checkErrors(source: SourceFile): Unit = compiler.getUnitOf(source) match {
20+
case Some(unit) =>
21+
val problems = unit.problems.toList
22+
if(problems.isEmpty) reporter.println("Test OK")
23+
else problems.foreach(problem => reporter.println(problem.msg))
24+
25+
case None => reporter.println("No compilation unit found for " + source.file.name)
26+
}
27+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package nodescala
2+
3+
class Foo
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package nodescala
2+
3+
class NodeScalaSuite {
4+
"".rich
5+
6+
// This is here only to prove that the presentation compiler is instantiated with the
7+
// correct `sourcepath` value (if it wasn't, you would see a `not found: type Foo` in
8+
// the test's output
9+
println(new Foo())
10+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import scala.Some // <-- if you move the import *inside* the package object, then it all works fine!!
2+
3+
package object nodescala {
4+
implicit class StringOps(val f: String) {
5+
def rich = 0
6+
}
7+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
reload: NodeScalaSuite.scala
2+
open package module: package nodescala
3+
Test OK
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-sourcepath src
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import scala.tools.nsc.interactive.tests.InteractiveTest
2+
import scala.reflect.internal.util.SourceFile
3+
import scala.tools.nsc.interactive.Response
4+
5+
object Test extends InteractiveTest {
6+
7+
override def execute(): Unit = {
8+
val src = loadSourceAndWaitUntilTypechecked("NodeScalaSuite.scala")
9+
checkErrors(src)
10+
}
11+
12+
private def loadSourceAndWaitUntilTypechecked(sourceName: String): SourceFile = {
13+
val sourceFile = sourceFiles.find(_.file.name == sourceName).head
14+
askReload(List(sourceFile)).get
15+
askLoadedTyped(sourceFile).get
16+
sourceFile
17+
}
18+
19+
private def checkErrors(source: SourceFile): Unit = compiler.getUnitOf(source) match {
20+
case Some(unit) =>
21+
val problems = unit.problems.toList
22+
if(problems.isEmpty) reporter.println("Test OK")
23+
else problems.foreach(problem => reporter.println(problem.msg))
24+
25+
case None => reporter.println("No compilation unit found for " + source.file.name)
26+
}
27+
}

0 commit comments

Comments
 (0)