summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@typesafe.com>2013-12-18 15:55:28 -0800
committerAdriaan Moors <adriaan.moors@typesafe.com>2013-12-18 15:55:28 -0800
commit97b9b2c06a5f562b749eb34834096118f21ca843 (patch)
tree842325683b4d5458e1ae639718a75c3bc32d25f7
parent5cbb5a7f626aa7bd305ad8ce2ad96ee742315536 (diff)
parent7e85b595502974bebf2f2625c6bc3645f0d3ab27 (diff)
downloadscala-97b9b2c06a5f562b749eb34834096118f21ca843.tar.gz
scala-97b9b2c06a5f562b749eb34834096118f21ca843.tar.bz2
scala-97b9b2c06a5f562b749eb34834096118f21ca843.zip
Merge pull request #3282 from retronym/ticket/8085
Fix BrowserTraverser for package objects
-rw-r--r--src/compiler/scala/tools/nsc/symtab/BrowsingLoaders.scala6
-rw-r--r--test/files/presentation/t8085.check3
-rw-r--r--test/files/presentation/t8085.flags1
-rw-r--r--test/files/presentation/t8085/Test.scala27
-rw-r--r--test/files/presentation/t8085/src/nodescala/Foo.scala3
-rw-r--r--test/files/presentation/t8085/src/nodescala/NodeScalaSuite.scala10
-rw-r--r--test/files/presentation/t8085/src/nodescala/package.scala7
-rw-r--r--test/files/presentation/t8085b.check3
-rw-r--r--test/files/presentation/t8085b.flags1
-rw-r--r--test/files/presentation/t8085b/Test.scala27
-rw-r--r--test/files/presentation/t8085b/src/p1/nodescala/Foo.scala4
-rw-r--r--test/files/presentation/t8085b/src/p1/nodescala/NodeScalaSuite.scala11
-rw-r--r--test/files/presentation/t8085b/src/p1/nodescala/package.scala9
13 files changed, 110 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/BrowsingLoaders.scala b/src/compiler/scala/tools/nsc/symtab/BrowsingLoaders.scala
index f2aab36b51..c7bd678385 100644
--- a/src/compiler/scala/tools/nsc/symtab/BrowsingLoaders.scala
+++ b/src/compiler/scala/tools/nsc/symtab/BrowsingLoaders.scala
@@ -64,8 +64,10 @@ abstract class BrowsingLoaders extends SymbolLoaders {
addPackagePrefix(pre)
packagePrefix += ("." + name)
case Ident(name) =>
- if (packagePrefix.length != 0) packagePrefix += "."
- packagePrefix += name
+ if (name != nme.EMPTY_PACKAGE_NAME) { // mirrors logic in Namers, see createPackageSymbol
+ if (packagePrefix.length != 0) packagePrefix += "."
+ packagePrefix += name
+ }
case _ =>
throw new MalformedInput(pkg.pos.point, "illegal tree node in package prefix: "+pkg)
}
diff --git a/test/files/presentation/t8085.check b/test/files/presentation/t8085.check
new file mode 100644
index 0000000000..79c1b2aa17
--- /dev/null
+++ b/test/files/presentation/t8085.check
@@ -0,0 +1,3 @@
+reload: NodeScalaSuite.scala
+open package module: package nodescala
+Test OK
diff --git a/test/files/presentation/t8085.flags b/test/files/presentation/t8085.flags
new file mode 100644
index 0000000000..ec35b223d8
--- /dev/null
+++ b/test/files/presentation/t8085.flags
@@ -0,0 +1 @@
+-sourcepath src
diff --git a/test/files/presentation/t8085/Test.scala b/test/files/presentation/t8085/Test.scala
new file mode 100644
index 0000000000..e46b7ab8c8
--- /dev/null
+++ b/test/files/presentation/t8085/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)
+ }
+}
diff --git a/test/files/presentation/t8085/src/nodescala/Foo.scala b/test/files/presentation/t8085/src/nodescala/Foo.scala
new file mode 100644
index 0000000000..19efdb65dd
--- /dev/null
+++ b/test/files/presentation/t8085/src/nodescala/Foo.scala
@@ -0,0 +1,3 @@
+package nodescala
+
+class Foo
diff --git a/test/files/presentation/t8085/src/nodescala/NodeScalaSuite.scala b/test/files/presentation/t8085/src/nodescala/NodeScalaSuite.scala
new file mode 100644
index 0000000000..45e43c7afb
--- /dev/null
+++ b/test/files/presentation/t8085/src/nodescala/NodeScalaSuite.scala
@@ -0,0 +1,10 @@
+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())
+}
diff --git a/test/files/presentation/t8085/src/nodescala/package.scala b/test/files/presentation/t8085/src/nodescala/package.scala
new file mode 100644
index 0000000000..26fb9f08e4
--- /dev/null
+++ b/test/files/presentation/t8085/src/nodescala/package.scala
@@ -0,0 +1,7 @@
+import scala.Some // <-- if you move the import *inside* the package object, then it all works fine!!
+
+package object nodescala {
+ implicit class StringOps(val f: String) {
+ def rich = 0
+ }
+}
diff --git a/test/files/presentation/t8085b.check b/test/files/presentation/t8085b.check
new file mode 100644
index 0000000000..79c1b2aa17
--- /dev/null
+++ b/test/files/presentation/t8085b.check
@@ -0,0 +1,3 @@
+reload: NodeScalaSuite.scala
+open package module: package nodescala
+Test OK
diff --git a/test/files/presentation/t8085b.flags b/test/files/presentation/t8085b.flags
new file mode 100644
index 0000000000..ec35b223d8
--- /dev/null
+++ b/test/files/presentation/t8085b.flags
@@ -0,0 +1 @@
+-sourcepath src
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)
+ }
+}
diff --git a/test/files/presentation/t8085b/src/p1/nodescala/Foo.scala b/test/files/presentation/t8085b/src/p1/nodescala/Foo.scala
new file mode 100644
index 0000000000..8ed1ada6b6
--- /dev/null
+++ b/test/files/presentation/t8085b/src/p1/nodescala/Foo.scala
@@ -0,0 +1,4 @@
+package p1
+package nodescala
+
+class Foo
diff --git a/test/files/presentation/t8085b/src/p1/nodescala/NodeScalaSuite.scala b/test/files/presentation/t8085b/src/p1/nodescala/NodeScalaSuite.scala
new file mode 100644
index 0000000000..f6da67bdc7
--- /dev/null
+++ b/test/files/presentation/t8085b/src/p1/nodescala/NodeScalaSuite.scala
@@ -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())
+}
diff --git a/test/files/presentation/t8085b/src/p1/nodescala/package.scala b/test/files/presentation/t8085b/src/p1/nodescala/package.scala
new file mode 100644
index 0000000000..cc383f1bab
--- /dev/null
+++ b/test/files/presentation/t8085b/src/p1/nodescala/package.scala
@@ -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
+ }
+ }
+}