Skip to content

Commit 7d87761

Browse files
committed
Fix #2888: Avoid caching supertypes of hk applications with provisional infos
If the type constructor of a hk application has a provisional info (because we are starting to initialize an F-bounded definition), we cannot cache its supertype. We get an empty bound if we do.
1 parent d121ad5 commit 7d87761

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,9 @@ object Flags {
424424
/** A method that is known to have no default parameters */
425425
final val NoDefaultParams = termFlag(61, "<no-default-param>")
426426

427+
/** A type symbol with provisional empty bounds */
428+
final val Provisional = typeFlag(61, "<provisional>")
429+
427430
/** A denotation that is valid in all run-ids */
428431
final val Permanent = commonFlag(62, "<permanent>")
429432

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3012,12 +3012,16 @@ object Types {
30123012

30133013
override def superType(implicit ctx: Context): Type = {
30143014
if (ctx.period != validSuper) {
3015+
var canCache = true
30153016
cachedSuper = tycon match {
30163017
case tp: HKTypeLambda => defn.AnyType
30173018
case tp: TypeVar if !tp.inst.exists =>
30183019
// supertype not stable, since underlying might change
3019-
return tp.underlying.applyIfParameterized(args)
3020-
case tp: TypeProxy => tp.superType.applyIfParameterized(args)
3020+
canCache = false
3021+
tp.underlying.applyIfParameterized(args)
3022+
case tp: TypeProxy =>
3023+
canCache = !tp.typeSymbol.is(Provisional)
3024+
tp.superType.applyIfParameterized(args)
30213025
case _ => defn.AnyType
30223026
}
30233027
validSuper = ctx.period

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,7 @@ class Namer { typer: Typer =>
11591159
def abstracted(tp: Type): Type = HKTypeLambda.fromParams(tparamSyms, tp)
11601160
val dummyInfo = abstracted(TypeBounds.empty)
11611161
sym.info = dummyInfo
1162+
sym.setFlag(Provisional)
11621163
// Temporarily set info of defined type T to ` >: Nothing <: Any.
11631164
// This is done to avoid cyclic reference errors for F-bounds.
11641165
// This is subtle: `sym` has now an empty TypeBounds, but is not automatically

0 commit comments

Comments
 (0)