Skip to content

Commit 29a2b2a

Browse files
oderskysmarter
authored andcommitted
Avoid caching the wrong bounds in TypeRefs
Checking bounds everywhere revealed a problem in compileStdLib, which this commit fixes.
1 parent d95de14 commit 29a2b2a

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,9 @@ class Namer { typer: Typer =>
850850
if (tparamSyms.nonEmpty && !isDerived) tp.LambdaAbstract(tparamSyms)
851851
//else if (toParameterize) tp.parameterizeWith(tparamSyms)
852852
else tp
853-
sym.info = abstracted(TypeBounds.empty)
853+
854+
val dummyInfo = abstracted(TypeBounds.empty)
855+
sym.info = dummyInfo
854856
// Temporarily set info of defined type T to ` >: Nothing <: Any.
855857
// This is done to avoid cyclic reference errors for F-bounds.
856858
// This is subtle: `sym` has now an empty TypeBounds, but is not automatically
@@ -871,6 +873,19 @@ class Namer { typer: Typer =>
871873
sym.info = NoCompleter
872874
sym.info = checkNonCyclic(sym, unsafeInfo, reportErrors = true)
873875
}
876+
877+
// Here we pay the price for the cavalier setting info to TypeBounds.empty above.
878+
// We need to compensate by invalidating caches in references that might
879+
// still contain the TypeBounds.empty. If we do not do this, stdlib factories
880+
// fail with a bounds error in PostTyper.
881+
def ensureUpToDate(tp: Type, outdated: Type) = tp match {
882+
case tref: TypeRef if tref.info == outdated && sym.info != outdated =>
883+
tref.uncheckedSetSym(null)
884+
case _ =>
885+
}
886+
ensureUpToDate(sym.typeRef, dummyInfo)
887+
ensureUpToDate(sym.typeRef.appliedTo(tparamSyms.map(_.typeRef)), TypeBounds.empty)
888+
874889
etaExpandArgs.apply(sym.info)
875890
}
876891

0 commit comments

Comments
 (0)