Skip to content

Commit a33258e

Browse files
authored
Merge pull request #2889 from dotty-staging/fix#-2888
Fix #2888: Avoid caching supertypes of hk apps with provisional infos
2 parents d121ad5 + 7800d22 commit a33258e

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3012,15 +3012,18 @@ object Types {
30123012

30133013
override def superType(implicit ctx: Context): Type = {
30143014
if (ctx.period != validSuper) {
3015+
validSuper = ctx.period
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+
validSuper = Nowhere
3021+
tp.underlying.applyIfParameterized(args)
3022+
case tp: TypeProxy =>
3023+
if (tp.typeSymbol.is(Provisional)) validSuper = Nowhere
3024+
tp.superType.applyIfParameterized(args)
30213025
case _ => defn.AnyType
30223026
}
3023-
validSuper = ctx.period
30243027
}
30253028
cachedSuper
30263029
}

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

tests/pos/i2888.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
trait Foo[A, CC[X] <: Foo[X, CC, CC[X]], C <: CC[A]] {
2+
3+
def cc: CC[A]
4+
5+
def foo: Unit = ()
6+
7+
def bar: Unit = cc.foo
8+
9+
}
10+
11+
object Main {
12+
def main(args: Array[String]): Unit = ()
13+
}

0 commit comments

Comments
 (0)