Skip to content

Commit 9753483

Browse files
committed
Fix signature caching in NamedType
Underdefined signatures cannot be cached, this matches the logic in MethodicType. I haven't managed to create a testcase that fails without this, but it should be the Right Thing to do anyway.
1 parent fd8f29c commit 9753483

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,6 +1593,7 @@ object Types {
15931593

15941594
private[this] var myName: Name = null
15951595
private[this] var mySig: Signature = null
1596+
private[this] var mySigRunId: Int = NoRunId
15961597
private[this] var lastDenotation: Denotation = null
15971598
private[this] var lastSymbol: Symbol = null
15981599
private[this] var checkedPeriod: Period = Nowhere
@@ -1601,6 +1602,7 @@ object Types {
16011602
// Invariants:
16021603
// (1) checkedPeriod != Nowhere => lastDenotation != null
16031604
// (2) lastDenotation != null => lastSymbol != null
1605+
// (3) mySigRunId != NoRunId => mySig != null
16041606

16051607
def isType = isInstanceOf[TypeRef]
16061608
def isTerm = isInstanceOf[TermRef]
@@ -1622,7 +1624,10 @@ object Types {
16221624
* signature of the symbol
16231625
*/
16241626
final override def signature(implicit ctx: Context): Signature = {
1625-
if (mySig == null) mySig = computeSignature
1627+
if (ctx.runId != mySigRunId) {
1628+
mySig = computeSignature
1629+
if (!mySig.isUnderDefined) mySigRunId = ctx.runId
1630+
}
16261631
mySig
16271632
}
16281633

@@ -1637,7 +1642,7 @@ object Types {
16371642
* Otherwise NotAMethod.
16381643
*/
16391644
private def currentSignature(implicit ctx: Context): Signature =
1640-
if (mySig != null) mySig
1645+
if (ctx.runId == mySigRunId) mySig
16411646
else {
16421647
val lastd = lastDenotation
16431648
if (lastd != null) lastd.signature

0 commit comments

Comments
 (0)