Permalink
Browse files

Test demonstrating SI-8085

* The presentation compiler sourcepath is now correctly set-up.
* Amazingly enough (for me at least), the outer import in the
  package object seem to be responsible of the faulty behavior.
  In fact, if you move the import clause *inside* the package object,
  the test succeed!
  The test's output does provide the correct hint of this:

```
% diff /Users/mirco/Projects/ide/scala/test/files/presentation/t8085-presentation.log /Users/mirco/Projects/ide/scala/test/files/presentation/t8085.check
@@ -1,3 +1,2 @@
 reload: NodeScalaSuite.scala
-prefixes differ: <empty>.nodescala,nodescala
-value always is not a member of object scala.concurrent.Future
+Test OK
```

Notice the ``-prefixes differ: <empty>.nodescala,nodescala``. And compare
it with the output when the import clause is placed inside the package
object:

```
% diff /Users/mirco/Projects/ide/scala/test/files/presentation/t8085-presentation.log /Users/mirco/Projects/ide/scala/test/files/presentation/t8085.check
@@ -1,4 +1,2 @@
 reload: NodeScalaSuite.scala
-reload: NodeScalaSuite.scala
-open package module: package object nodescala
 Test OK
```

Notice now the ``-open package module: package object nodescala``!
  • Loading branch information...
1 parent 5cbb5a7 commit a12dd9c3b6fb4a767eec8f6d3bf0a9a2266eff85 @dotta dotta committed with retronym Dec 10, 2013
@@ -0,0 +1,3 @@
+reload: NodeScalaSuite.scala
+prefixes differ: <empty>.nodescala,nodescala
+value always is not a member of object scala.concurrent.Future
@@ -0,0 +1 @@
+-sourcepath src
@@ -0,0 +1,28 @@
+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 = {
+ // loadSourceAndWaitUntilTypechecked("package.scala") // <-- uncomment this line and the test succeed
+ 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)
+ }
+}
@@ -0,0 +1,3 @@
+package nodescala
+
+class Foo
@@ -0,0 +1,12 @@
+package nodescala
+
+import scala.concurrent.Future
+
+class NodeScalaSuite {
+ Future.always(517)
+
+ // 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())
+}
@@ -0,0 +1,8 @@
+import scala.concurrent.Future // <-- 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
+ }
+}
+

0 comments on commit a12dd9c

Please sign in to comment.