Skip to content

Commit fd7d874

Browse files
committed
Reduce match types in superType instead of translucentSuperType
1 parent 942897d commit fd7d874

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,7 +1881,9 @@ object Types {
18811881
/** The closest supertype of this type. This is the same as `underlying`,
18821882
* except that
18831883
* - instead of a TyperBounds type it returns its upper bound, and
1884-
* - for applied types it returns the upper bound of the constructor re-applied to the arguments.
1884+
* - for applied types it returns
1885+
* * if the applied type can be matchtype-reduced, the redux
1886+
* * otherwise, the upper bound of the constructor re-applied to the arguments.
18851887
*/
18861888
def superType(using Context): Type = underlying match {
18871889
case TypeBounds(_, hi) => hi
@@ -3996,12 +3998,15 @@ object Types {
39963998

39973999
override def superType(using Context): Type = {
39984000
if (ctx.period != validSuper) {
3999-
cachedSuper = tycon match {
4000-
case tycon: HKTypeLambda => defn.AnyType
4001-
case tycon: TypeRef if tycon.symbol.isClass => tycon
4002-
case tycon: TypeProxy => tycon.superType.applyIfParameterized(args)
4003-
case _ => defn.AnyType
4004-
}
4001+
cachedSuper = tycon match
4002+
case tycon: HKTypeLambda =>
4003+
defn.AnyType
4004+
case tycon: TypeRef if tycon.symbol.isClass =>
4005+
tycon
4006+
case tycon: TypeProxy =>
4007+
tryNormalize.orElse(tycon.superType.applyIfParameterized(args))
4008+
case _ =>
4009+
defn.AnyType
40054010
validSuper = if (tycon.isProvisional) Nowhere else ctx.period
40064011
}
40074012
cachedSuper
@@ -4011,7 +4016,7 @@ object Types {
40114016
case tycon: TypeRef if tycon.symbol.isOpaqueAlias =>
40124017
tycon.translucentSuperType.applyIfParameterized(args)
40134018
case _ =>
4014-
tryNormalize.orElse(superType)
4019+
superType
40154020
}
40164021

40174022
inline def map(inline op: Type => Type)(using Context) =

0 commit comments

Comments
 (0)