Skip to content

Commit 7ada264

Browse files
committed
Fix #5333: Invalid entries in the baseType cache
Provisional types should not have their baseType cached, it may change as type variables get refined and instantiated. The seqtype-cycle test had to be adjusted to avoid some missing reference errors, probably due to the completion order changing.
1 parent 0fcbfdb commit 7ada264

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,7 +1631,10 @@ object SymDenotations {
16311631
Stats.record("basetype cache entries")
16321632
if (!baseTp.exists) Stats.record("basetype cache NoTypes")
16331633
}
1634-
btrCache.put(tp, baseTp)
1634+
if (!tp.isProvisional)
1635+
btrCache.put(tp, baseTp)
1636+
else
1637+
btrCache.remove(tp) // Remove any potential sentinel value
16351638
}
16361639

16371640
def ensureAcyclic(baseTp: Type) = {
@@ -1717,8 +1720,6 @@ object SymDenotations {
17171720
val baseTp = recur(superTp)
17181721
tp match {
17191722
case tp: CachedType if baseTp.exists && inCache(superTp) =>
1720-
// Note: This also works for TypeVars: If they are not instantiated, their supertype
1721-
// is a TypeParamRef, which is never cached. So uninstantiated TypeVars are not cached either.
17221723
record(tp, baseTp)
17231724
case _ =>
17241725
}

tests/pos/seqtype-cycle/Test2.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package object scala {
22
// needed for some reasons
33
type Throwable = java.lang.Throwable
44
type IndexOutOfBoundsException = java.lang.IndexOutOfBoundsException
5+
type List[+A] = scala.collection.immutable.List[A]
6+
type Iterable[+A] = scala.collection.Iterable[A]
57

68
type Seq[A] = scala.collection.Seq[A]
79
val Seq = scala.collection.Seq

0 commit comments

Comments
 (0)