Skip to content

Commit a0839bc

Browse files
Use cached underlyingMatchType when normalizing applied match aliases
Also fixes underlyingMatchType to not use the resType of HKTypeLambdas It should only be in `isMatch` used for `AliasingBounds`, not `isMatchAlias`
1 parent ee323ef commit a0839bc

File tree

1 file changed

+11
-25
lines changed

1 file changed

+11
-25
lines changed

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

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -468,12 +468,10 @@ object Types extends TypeUtils {
468468
/** Does this application expand to a match type? */
469469
def isMatchAlias(using Context): Boolean = underlyingMatchType.exists
470470

471-
def underlyingMatchType(using Context): Type = stripped match {
471+
def underlyingMatchType(using Context): Type = stripped match
472472
case tp: MatchType => tp
473-
case tp: HKTypeLambda => tp.resType.underlyingMatchType
474473
case tp: AppliedType => tp.underlyingMatchType
475474
case _ => NoType
476-
}
477475

478476
/** Is this a higher-kinded type lambda with given parameter variances?
479477
* These lambdas are used as the RHS of higher-kinded abstract types or
@@ -4647,35 +4645,23 @@ object Types extends TypeUtils {
46474645

46484646
/** Exists if the tycon is a TypeRef of an alias with an underlying match type.
46494647
* Anything else should have already been reduced in `appliedTo` by the TypeAssigner.
4648+
* May reduce several HKTypeLambda applications before the underlying MatchType is reached.
46504649
*/
46514650
override def underlyingMatchType(using Context): Type =
46524651
if ctx.period != validUnderlyingMatch then
46534652
validUnderlyingMatch = if tycon.isProvisional then Nowhere else ctx.period
46544653
cachedUnderlyingMatch = superType.underlyingMatchType
46554654
cachedUnderlyingMatch
46564655

4657-
override def tryNormalize(using Context): Type = tycon.stripTypeVar match {
4658-
case tycon: TypeRef =>
4659-
def tryMatchAlias = tycon.info match
4660-
case AliasingBounds(alias) if isMatchAlias =>
4661-
trace(i"normalize $this", typr, show = true) {
4662-
MatchTypeTrace.recurseWith(this) {
4663-
alias.applyIfParameterized(args).tryNormalize
4664-
/* `applyIfParameterized` may reduce several HKTypeLambda applications
4665-
* before the underlying MatchType is reached.
4666-
* Even if they do not involve any match type normalizations yet,
4667-
* we still want to record these reductions in the MatchTypeTrace.
4668-
* They should however only be attempted if they eventually expand
4669-
* to a match type, which is ensured by the `isMatchAlias` guard.
4670-
*/
4671-
}
4672-
}
4673-
case _ =>
4674-
NoType
4675-
tryCompiletimeConstantFold.orElse(tryMatchAlias)
4676-
case _ =>
4677-
NoType
4678-
}
4656+
override def tryNormalize(using Context): Type =
4657+
def tryMatchAlias =
4658+
if isMatchAlias then trace(i"normalize $this", typr, show = true):
4659+
if MatchTypeTrace.isRecording then
4660+
MatchTypeTrace.recurseWith(this)(superType.tryNormalize)
4661+
else
4662+
underlyingMatchType.tryNormalize
4663+
else NoType
4664+
tryCompiletimeConstantFold.orElse(tryMatchAlias)
46794665

46804666
/** Is this an unreducible application to wildcard arguments?
46814667
* This is the case if tycon is higher-kinded. This means

0 commit comments

Comments
 (0)