Skip to content

Commit 1b37350

Browse files
committed
Don't normalize in AppliedType#superType
1 parent fb6d004 commit 1b37350

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
@@ -1950,6 +1950,7 @@ object Types {
19501950
case TypeBounds(_, hi) => hi
19511951
case st => st
19521952
}
1953+
def superTypeNormalized(using Context): Type = superType.normalized
19531954

19541955
/** Same as superType, except for two differences:
19551956
* - opaque types are treated as transparent aliases
@@ -4199,10 +4200,28 @@ object Types {
41994200
case tycon: TypeRef if tycon.symbol.isClass => tycon
42004201
case tycon: TypeProxy =>
42014202
if isMatchAlias then validSuper = Nowhere
4202-
tycon.superType.applyIfParameterized(args).normalized
4203+
val was = tycon.superType.applyIfParameterized(args)
4204+
if false then
4205+
val now = was.normalized
4206+
if was ne now then
4207+
println(i"norm $was / $now")
4208+
new Error().printStackTrace()
4209+
was
42034210
case _ => defn.AnyType
42044211
cachedSuper
42054212

4213+
override def superTypeNormalized(using Context) =
4214+
if ctx.period != validSuper then
4215+
validSuper = if (tycon.isProvisional) Nowhere else ctx.period
4216+
cachedSuper = tycon match
4217+
case tycon: HKTypeLambda => defn.AnyType
4218+
case tycon: TypeRef if tycon.symbol.isClass => tycon
4219+
case tycon: TypeProxy =>
4220+
if isMatchAlias then validSuper = Nowhere
4221+
tycon.superType.applyIfParameterized(args)
4222+
case _ => defn.AnyType
4223+
cachedSuper.normalized
4224+
42064225
override def translucentSuperType(using Context): Type = tycon match {
42074226
case tycon: TypeRef if tycon.symbol.isOpaqueAlias =>
42084227
tycon.translucentSuperType.applyIfParameterized(args)

0 commit comments

Comments
 (0)