@@ -1317,6 +1317,18 @@ object SymDenotations {
1317
1317
case _ => bt
1318
1318
}
1319
1319
1320
+ def inCache (tp : Type ) = baseTypeRefCache.containsKey(tp)
1321
+
1322
+ /** Can't cache types containing type variables which are uninstantiated
1323
+ * or whose instances can change, depending on typerstate.
1324
+ */
1325
+ def isCachable (tp : Type ): Boolean = tp match {
1326
+ case tp : TypeProxy => inCache(tp.underlying)
1327
+ case tp : AndOrType => inCache(tp.tp1) && inCache(tp.tp2)
1328
+ case tp : TypeVar => tp.inst.exists && inCache(tp.inst)
1329
+ case _ => true
1330
+ }
1331
+
1320
1332
def computeBaseTypeRefOf (tp : Type ): Type = {
1321
1333
Stats .record(" computeBaseTypeOf" )
1322
1334
if (symbol.isStatic && tp.derivesFrom(symbol))
@@ -1333,9 +1345,6 @@ object SymDenotations {
1333
1345
case _ =>
1334
1346
baseTypeRefOf(tp.underlying)
1335
1347
}
1336
- case tp : TypeVar =>
1337
- if (tp.inst.exists) computeBaseTypeRefOf(tp.inst)
1338
- else Uncachable (computeBaseTypeRefOf(tp.underlying))
1339
1348
case tp : TypeProxy =>
1340
1349
baseTypeRefOf(tp.underlying)
1341
1350
case AndType (tp1, tp2) =>
@@ -1356,15 +1365,9 @@ object SymDenotations {
1356
1365
var basetp = baseTypeRefCache get tp
1357
1366
if (basetp == null ) {
1358
1367
baseTypeRefCache.put(tp, NoPrefix )
1359
- val computedBT = computeBaseTypeRefOf(tp)
1360
- basetp = computedBT match {
1361
- case Uncachable (basetp) =>
1362
- baseTypeRefCache.remove(tp)
1363
- computedBT
1364
- case basetp =>
1365
- baseTypeRefCache.put(tp, basetp)
1366
- basetp
1367
- }
1368
+ basetp = computeBaseTypeRefOf(tp)
1369
+ if (isCachable(tp)) baseTypeRefCache.put(tp, basetp)
1370
+ else baseTypeRefCache.remove(tp)
1368
1371
} else if (basetp == NoPrefix ) {
1369
1372
throw CyclicReference (this )
1370
1373
}
@@ -1444,8 +1447,7 @@ object SymDenotations {
1444
1447
copySymDenotation(info = ClassInfo (pre, classSymbol, ps, decls.cloneScope, selfInfo))
1445
1448
.installAfter(phase)
1446
1449
}
1447
- }
1448
- private case class Uncachable (tp : Type ) extends UncachedGroundType
1450
+ }
1449
1451
1450
1452
/** The denotation of a package class.
1451
1453
* It overrides ClassDenotation to take account of package objects when looking for members
0 commit comments