Skip to content

Commit 16e3b14

Browse files
committed
Made TypeVars uncahable keys
TypeVars can appear as keys in baseType caches. The problem is that their base types depend on their instantiation, which is not always know yet when the test is performed. So results of baseType on type variables should never be cached. Todo: check whether there are any other caching problems involving typevars.
1 parent 394d8d0 commit 16e3b14

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,6 +1326,9 @@ object SymDenotations {
13261326
case _ =>
13271327
baseTypeRefOf(tp.underlying)
13281328
}
1329+
case tp: TypeVar =>
1330+
if (tp.inst.exists) computeBaseTypeRefOf(tp.inst)
1331+
else Uncachable(computeBaseTypeRefOf(tp.underlying))
13291332
case tp: TypeProxy =>
13301333
baseTypeRefOf(tp.underlying)
13311334
case AndType(tp1, tp2) =>
@@ -1346,8 +1349,14 @@ object SymDenotations {
13461349
var basetp = baseTypeRefCache get tp
13471350
if (basetp == null) {
13481351
baseTypeRefCache.put(tp, NoPrefix)
1349-
basetp = computeBaseTypeRefOf(tp)
1350-
baseTypeRefCache.put(tp, basetp)
1352+
basetp = computeBaseTypeRefOf(tp) match {
1353+
case Uncachable(basetp) =>
1354+
baseTypeRefCache.remove(tp)
1355+
basetp
1356+
case basetp =>
1357+
baseTypeRefCache.put(tp, basetp)
1358+
basetp
1359+
}
13511360
} else if (basetp == NoPrefix) {
13521361
throw CyclicReference(this)
13531362
}
@@ -1427,7 +1436,9 @@ object SymDenotations {
14271436
copySymDenotation(info = ClassInfo(pre, classSymbol, ps, decls.cloneScope, selfInfo))
14281437
.installAfter(phase)
14291438
}
1430-
}
1439+
}
1440+
1441+
private case class Uncachable(tp: Type) extends UncachedGroundType
14311442

14321443
/** The denotation of a package class.
14331444
* It overrides ClassDenotation to take account of package objects when looking for members

0 commit comments

Comments
 (0)