|
| 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 SignatureTest: |
| 16 | + @Test def signatureCaching: Unit = |
| 17 | + inCompilerContext(TestConfiguration.basicClasspath, separateRun = true, "case class Foo(value: Unit)") { |
| 18 | + val (ref, refSig) = ctx.atPhase(ctx.erasurePhase.next) { |
| 19 | + val cls = ctx.requiredClass("Foo") |
| 20 | + val ref = cls.requiredMethod("value").termRef |
| 21 | + (ref, ref.signature) |
| 22 | + } |
| 23 | + ctx.atPhase(ctx.typerPhase) { |
| 24 | + // NamedType#signature is always computed before erasure, which ensures |
| 25 | + // that it stays stable and therefore can be cached as long as |
| 26 | + // signatures are guaranteed to be stable before erasure, see the |
| 27 | + // comment above `Compiler#phases`. |
| 28 | + assert(refSig == ref.signature, |
| 29 | + s"""The signature of a type should never change but the signature of $ref was: |
| 30 | + |${ref.signature} at typer, whereas it was: |
| 31 | + |${refSig} after erasure""".stripMargin) |
| 32 | + assert(ref.signature == ref.denot.signature, |
| 33 | + s"""Before erasure, the signature of a TypeRef should be the signature of its denotation, |
| 34 | + |but the cached signature of $ref was: |
| 35 | + |${ref.signature}, whereas its denotation signature at typer was: |
| 36 | + |${ref.denot.signature}""".stripMargin) |
| 37 | + } |
| 38 | + } |
0 commit comments