File tree Expand file tree Collapse file tree 2 files changed +43
-3
lines changed
compiler/test/dotty/tools Expand file tree Collapse file tree 2 files changed +43
-3
lines changed Original file line number Diff line number Diff line change
1
+ package dotty .tools
2
+
3
+ import vulpix .TestConfiguration
4
+
5
+ import org .junit .Test
6
+
7
+ import dotc .ast .Trees ._
8
+ import dotc .core .Decorators ._
9
+ import dotc .core .Contexts ._
10
+ import dotc .core .Types ._
11
+
12
+ import java .io .File
13
+ import java .nio .file ._
14
+
15
+ class SignaturesTest :
16
+ @ Test def signatureCaching : Unit =
17
+ inCompilerContext(TestConfiguration .basicClasspath, " case class Foo(value: Unit)" ) {
18
+ val defn = ctx.definitions
19
+ val leftCls = ctx.requiredClass(" Foo" )
20
+ val ref = leftCls.requiredMethod(" value" ).termRef
21
+
22
+ def checkSig ()(using Context ): Unit =
23
+ val denot = ref.denot
24
+ assert(ref.signature == denot.signature, i " Wrong cached signature at phase ${ctx.phase} for $ref. \n Actual denotation signature: ${denot.signature}\n Cached ref signature: ${ref.signature}" )
25
+
26
+ checkSig()
27
+ checkSig()(using ctx.withPhase(ctx.erasurePhase.next))
28
+ }
Original file line number Diff line number Diff line change 1
1
package dotty .tools
2
2
3
3
import javax .tools ._
4
- import java .io .File
4
+ import java .io ._
5
5
import java .nio .file ._
6
6
import java .net .URI
7
7
import scala .jdk .CollectionConverters ._
@@ -10,13 +10,25 @@ import core._
10
10
import core .Contexts ._
11
11
import dotc .core .Comments .{ContextDoc , ContextDocstrings }
12
12
13
+ // TODO: refactor, copy-pasted from Run#compileFromStrings
14
+ private def sourceFile (source : String , isJava : Boolean ): util.SourceFile = {
15
+ val uuid = java.util.UUID .randomUUID().toString
16
+ val ext = if (isJava) " .java" else " .scala"
17
+ val virtualFile = new io.VirtualFile (s " compileFromString- $uuid. $ext" )
18
+ val writer = new BufferedWriter (new OutputStreamWriter (virtualFile.output, " UTF-8" )) // buffering is still advised by javadoc
19
+ writer.write(source)
20
+ writer.close()
21
+ new util.SourceFile (virtualFile, scala.io.Codec .UTF8 )
22
+ }
23
+
13
24
/** Initialize a compiler context with the given classpath and
14
25
* pass it to `op`.
15
26
*/
16
- def inCompilerContext [T ](classpath : String )(op : Context ?=> T ): T =
27
+ def inCompilerContext [T ](classpath : String , scalaSources : String * )(op : Context ?=> T ): T =
17
28
val compiler = Compiler ()
18
29
val run = compiler.newRun(initCtx(classpath))
19
- run.compileUnits(Nil ) // Initialize phases
30
+ run.compileUnits(scalaSources.toList.map(s =>
31
+ CompilationUnit (sourceFile(s, isJava = false ))(using run.runContext)))
20
32
op(using run.runContext)
21
33
22
34
private def initCtx (classpath : String ): Context =
You can’t perform that action at this time.
0 commit comments