Skip to content

Commit e4279d5

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 adaa489 commit e4279d5

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
@@ -869,7 +869,9 @@ class Namer { typer: Typer =>
869869
if (tparamSyms.nonEmpty && !isDerived) tp.LambdaAbstract(tparamSyms)
870870
//else if (toParameterize) tp.parameterizeWith(tparamSyms)
871871
else tp
872-
sym.info = abstracted(TypeBounds.empty)
872+
873+
val dummyInfo = abstracted(TypeBounds.empty)
874+
sym.info = dummyInfo
873875
// Temporarily set info of defined type T to ` >: Nothing <: Any.
874876
// This is done to avoid cyclic reference errors for F-bounds.
875877
// This is subtle: `sym` has now an empty TypeBounds, but is not automatically
@@ -890,6 +892,19 @@ class Namer { typer: Typer =>
890892
sym.info = NoCompleter
891893
sym.info = checkNonCyclic(sym, unsafeInfo, reportErrors = true)
892894
}
895+
896+
// Here we pay the price for the cavalier setting info to TypeBounds.empty above.
897+
// We need to compensate by invalidating caches in references that might
898+
// still contain the TypeBounds.empty. If we do not do this, stdlib factories
899+
// fail with a bounds error in PostTyper.
900+
def ensureUpToDate(tp: Type, outdated: Type) = tp match {
901+
case tref: TypeRef if tref.info == outdated && sym.info != outdated =>
902+
tref.uncheckedSetSym(null)
903+
case _ =>
904+
}
905+
ensureUpToDate(sym.typeRef, dummyInfo)
906+
ensureUpToDate(sym.typeRef.appliedTo(tparamSyms.map(_.typeRef)), TypeBounds.empty)
907+
893908
etaExpandArgs.apply(sym.info)
894909
}
895910

0 commit comments

Comments
 (0)