Skip to content

Commit cafc0bb

Browse files
committed
Don't normalize in AppliedType#superType
1 parent 34336af commit cafc0bb

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
11121112
if tycon1sym == tycon2sym && tycon1sym.isAliasType then
11131113
val preConstraint = constraint
11141114
isSubArgs(args1, args2, tp1, tparams)
1115-
&& tryAlso(preConstraint, recur(tp1.superType, tp2.superType))
1115+
&& tryAlso(preConstraint, recur(tp1.superTypeNormalized, tp2.superTypeNormalized))
11161116
else
11171117
isSubArgs(args1, args2, tp1, tparams)
11181118
}
@@ -1177,7 +1177,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
11771177
*/
11781178
def compareLower(tycon2bounds: TypeBounds, tyconIsTypeRef: Boolean): Boolean =
11791179
if ((tycon2bounds.lo `eq` tycon2bounds.hi) && !tycon2bounds.isInstanceOf[MatchAlias])
1180-
if (tyconIsTypeRef) recur(tp1, tp2.superType)
1180+
if (tyconIsTypeRef) recur(tp1, tp2.superTypeNormalized)
11811181
else isSubApproxHi(tp1, tycon2bounds.lo.applyIfParameterized(args2))
11821182
else
11831183
fallback(tycon2bounds.lo)
@@ -1249,11 +1249,11 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
12491249

12501250
!sym.isClass && {
12511251
defn.isCompiletimeAppliedType(sym) && compareCompiletimeAppliedType(tp1, tp2, fromBelow = false) ||
1252-
recur(tp1.superType, tp2) ||
1252+
recur(tp1.superTypeNormalized, tp2) ||
12531253
tryLiftedToThis1
12541254
}|| byGadtBounds
12551255
case tycon1: TypeProxy =>
1256-
recur(tp1.superType, tp2)
1256+
recur(tp1.superTypeNormalized, tp2)
12571257
case _ =>
12581258
false
12591259
}
@@ -2645,9 +2645,11 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
26452645
!(tp2 <:< tp1)
26462646
&& (provablyDisjoint(tp1, tp2.tp2) || provablyDisjoint(tp1, tp2.tp1))
26472647
case (tp1: NamedType, _) if gadtBounds(tp1.symbol) != null =>
2648-
provablyDisjoint(gadtBounds(tp1.symbol).uncheckedNN.hi, tp2) || provablyDisjoint(tp1.superType, tp2)
2648+
provablyDisjoint(gadtBounds(tp1.symbol).uncheckedNN.hi, tp2)
2649+
|| provablyDisjoint(tp1.superTypeNormalized, tp2)
26492650
case (_, tp2: NamedType) if gadtBounds(tp2.symbol) != null =>
2650-
provablyDisjoint(tp1, gadtBounds(tp2.symbol).uncheckedNN.hi) || provablyDisjoint(tp1, tp2.superType)
2651+
provablyDisjoint(tp1, gadtBounds(tp2.symbol).uncheckedNN.hi)
2652+
|| provablyDisjoint(tp1, tp2.superTypeNormalized)
26512653
case (tp1: TermRef, tp2: TermRef) if isEnumValueOrModule(tp1) && isEnumValueOrModule(tp2) =>
26522654
tp1.termSymbol != tp2.termSymbol
26532655
case (tp1: TermRef, tp2: TypeRef) if isEnumValue(tp1) =>
@@ -2663,11 +2665,11 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
26632665
case (tp1: Type, tp2: Type) if defn.isTupleNType(tp2) =>
26642666
provablyDisjoint(tp1, tp2.toNestedPairs)
26652667
case (tp1: TypeProxy, tp2: TypeProxy) =>
2666-
provablyDisjoint(tp1.superType, tp2) || provablyDisjoint(tp1, tp2.superType)
2668+
provablyDisjoint(tp1.superTypeNormalized, tp2) || provablyDisjoint(tp1, tp2.superTypeNormalized)
26672669
case (tp1: TypeProxy, _) =>
2668-
provablyDisjoint(tp1.superType, tp2)
2670+
provablyDisjoint(tp1.superTypeNormalized, tp2)
26692671
case (_, tp2: TypeProxy) =>
2670-
provablyDisjoint(tp1, tp2.superType)
2672+
provablyDisjoint(tp1, tp2.superTypeNormalized)
26712673
case _ =>
26722674
false
26732675
}

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1949,6 +1949,7 @@ object Types {
19491949
case TypeBounds(_, hi) => hi
19501950
case st => st
19511951
}
1952+
def superTypeNormalized(using Context): Type = superType.normalized
19521953

19531954
/** Same as superType, except for two differences:
19541955
* - opaque types are treated as transparent aliases
@@ -4176,10 +4177,28 @@ object Types {
41764177
case tycon: TypeRef if tycon.symbol.isClass => tycon
41774178
case tycon: TypeProxy =>
41784179
if isMatchAlias then validSuper = Nowhere
4179-
tycon.superType.applyIfParameterized(args).normalized
4180+
val was = tycon.superType.applyIfParameterized(args)
4181+
if false then
4182+
val now = was.normalized
4183+
if was ne now then
4184+
println(i"norm $was / $now")
4185+
new Error().printStackTrace()
4186+
was
41804187
case _ => defn.AnyType
41814188
cachedSuper
41824189

4190+
override def superTypeNormalized(using Context) =
4191+
if ctx.period != validSuper then
4192+
validSuper = if (tycon.isProvisional) Nowhere else ctx.period
4193+
cachedSuper = tycon match
4194+
case tycon: HKTypeLambda => defn.AnyType
4195+
case tycon: TypeRef if tycon.symbol.isClass => tycon
4196+
case tycon: TypeProxy =>
4197+
if isMatchAlias then validSuper = Nowhere
4198+
tycon.superType.applyIfParameterized(args)
4199+
case _ => defn.AnyType
4200+
cachedSuper.normalized
4201+
41834202
override def translucentSuperType(using Context): Type = tycon match {
41844203
case tycon: TypeRef if tycon.symbol.isOpaqueAlias =>
41854204
tycon.translucentSuperType.applyIfParameterized(args)

0 commit comments

Comments
 (0)