diff --git a/compiler/src/dotty/tools/dotc/Run.scala b/compiler/src/dotty/tools/dotc/Run.scala index a58ee0723107..7444dc2a9c61 100644 --- a/compiler/src/dotty/tools/dotc/Run.scala +++ b/compiler/src/dotty/tools/dotc/Run.scala @@ -239,8 +239,8 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint } } - def compile(sourceCode: String): Unit = { - val virtualFile = new VirtualFile(sourceCode) + def compileFromString(sourceCode: String): Unit = { + val virtualFile = new VirtualFile("compileFromString-${java.util.UUID.randomUUID().toString}") val writer = new BufferedWriter(new OutputStreamWriter(virtualFile.output, "UTF-8")) // buffering is still advised by javadoc writer.write(sourceCode) writer.close() diff --git a/compiler/src/dotty/tools/dotc/interactive/InteractiveDriver.scala b/compiler/src/dotty/tools/dotc/interactive/InteractiveDriver.scala index df4aef1b8f66..7d623b296dc2 100644 --- a/compiler/src/dotty/tools/dotc/interactive/InteractiveDriver.scala +++ b/compiler/src/dotty/tools/dotc/interactive/InteractiveDriver.scala @@ -296,7 +296,8 @@ class InteractiveDriver(val settings: List[String]) extends Driver { } private def toSource(uri: URI, sourceCode: String): SourceFile = { - val virtualFile = new VirtualFile(uri.toString, Paths.get(uri).toString) + val path = Paths.get(uri) + val virtualFile = new VirtualFile(path.getFileName.toString, path.toString) val writer = new BufferedWriter(new OutputStreamWriter(virtualFile.output, "UTF-8")) writer.write(sourceCode) writer.close() diff --git a/compiler/test/dotty/tools/DottyTest.scala b/compiler/test/dotty/tools/DottyTest.scala index 2304187527a4..ae7fd1337d97 100644 --- a/compiler/test/dotty/tools/DottyTest.scala +++ b/compiler/test/dotty/tools/DottyTest.scala @@ -64,14 +64,7 @@ trait DottyTest extends ContextEscapeDetection { def checkCompile(checkAfterPhase: String, source: String)(assertion: (tpd.Tree, Context) => Unit): Context = { val c = compilerWithChecker(checkAfterPhase)(assertion) val run = c.newRun - run.compile(source) - run.runContext - } - - def checkCompile(checkAfterPhase: String, sources: List[String])(assertion: (tpd.Tree, Context) => Unit): Context = { - val c = compilerWithChecker(checkAfterPhase)(assertion) - val run = c.newRun - run.compile(sources) + run.compileFromString(source) run.runContext } diff --git a/compiler/test/dotty/tools/backend/jvm/DottyBytecodeTest.scala b/compiler/test/dotty/tools/backend/jvm/DottyBytecodeTest.scala index c66386e97c89..f547c3576aab 100644 --- a/compiler/test/dotty/tools/backend/jvm/DottyBytecodeTest.scala +++ b/compiler/test/dotty/tools/backend/jvm/DottyBytecodeTest.scala @@ -58,7 +58,7 @@ trait DottyBytecodeTest { val compiler = new Compiler val run = compiler.newRun - compiler.newRun.compile(source) + compiler.newRun.compileFromString(source) checkOutput(ctx.settings.outputDir.value) } diff --git a/language-server/test/dotty/tools/languageserver/HoverTest.scala b/language-server/test/dotty/tools/languageserver/HoverTest.scala index 3ee0d1f53089..a753f4ed4901 100644 --- a/language-server/test/dotty/tools/languageserver/HoverTest.scala +++ b/language-server/test/dotty/tools/languageserver/HoverTest.scala @@ -200,4 +200,13 @@ class HoverTest { .hover(m3 to m4, hoverContent("Test.🤪")) } + + @Test def topLevel: Unit = { + code"""package hello + |val x: Int = 1 + |val y = ${m1}this${m2}.x""".withSource + // The test framework will place the code above in a virtual file called Source0.scala, + // sp the top-level definitions should be enclosed in an object called `Source0$package`. + .hover(m1 to m2, hoverContent("hello.Source0$package.type(hello.Source0$package)")) + } }