Skip to content

Commit a12dd9c

Browse files
dottaretronym
authored andcommitted
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``!
1 parent 5cbb5a7 commit a12dd9c

File tree

6 files changed

+55
-0
lines changed

6 files changed

+55
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
reload: NodeScalaSuite.scala
2+
prefixes differ: <empty>.nodescala,nodescala
3+
value always is not a member of object scala.concurrent.Future
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-sourcepath src
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
// loadSourceAndWaitUntilTypechecked("package.scala") // <-- uncomment this line and the test succeed
9+
val src = loadSourceAndWaitUntilTypechecked("NodeScalaSuite.scala")
10+
checkErrors(src)
11+
}
12+
13+
private def loadSourceAndWaitUntilTypechecked(sourceName: String): SourceFile = {
14+
val sourceFile = sourceFiles.find(_.file.name == sourceName).head
15+
askReload(List(sourceFile)).get
16+
askLoadedTyped(sourceFile).get
17+
sourceFile
18+
}
19+
20+
private def checkErrors(source: SourceFile): Unit = compiler.getUnitOf(source) match {
21+
case Some(unit) =>
22+
val problems = unit.problems.toList
23+
if(problems.isEmpty) reporter.println("Test OK")
24+
else problems.foreach(problem => reporter.println(problem.msg))
25+
26+
case None => reporter.println("No compilation unit found for " + source.file.name)
27+
}
28+
}
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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package nodescala
2+
3+
import scala.concurrent.Future
4+
5+
class NodeScalaSuite {
6+
Future.always(517)
7+
8+
// This is here only to prove that the presentation compiler is instantiated with the
9+
// correct `sourcepath` value (if it wasn't, you would see a `not found: type Foo` in
10+
// the test's output
11+
println(new Foo())
12+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import scala.concurrent.Future // <-- if you move the import *inside* the package object, then it all works fine!!
2+
3+
package object nodescala {
4+
implicit class FutureCompanionOps[T](val f: Future.type) extends AnyVal {
5+
def always[T](value: T): Future[T] = Promise[T].success(value).future
6+
}
7+
}
8+

0 commit comments

Comments
 (0)