@@ -489,11 +489,11 @@ object Types extends TypeUtils {
489489 case _ => false
490490
491491 /** Does this application expand to a match type? */
492- def isMatchAlias (using Context ): Boolean = underlyingMatchType.exists
492+ def isMatchAlias (using Context ): Boolean = underlyingNormalizable.isMatch
493493
494- def underlyingMatchType (using Context ): Type = stripped match
494+ def underlyingNormalizable (using Context ): Type = stripped match
495495 case tp : MatchType => tp
496- case tp : AppliedType => tp.underlyingMatchType
496+ case tp : AppliedType => tp.underlyingNormalizable
497497 case _ => NoType
498498
499499 /** Is this a higher-kinded type lambda with given parameter variances?
@@ -4612,8 +4612,8 @@ object Types extends TypeUtils {
46124612 private var myEvalRunId : RunId = NoRunId
46134613 private var myEvalued : Type = uninitialized
46144614
4615- private var validUnderlyingMatch : Period = Nowhere
4616- private var cachedUnderlyingMatch : Type = uninitialized
4615+ private var validUnderlyingNormalizable : Period = Nowhere
4616+ private var cachedUnderlyingNormalizable : Type = uninitialized
46174617
46184618 def isGround (acc : TypeAccumulator [Boolean ])(using Context ): Boolean =
46194619 if myGround == 0 then myGround = if acc.foldOver(true , this ) then 1 else - 1
@@ -4681,19 +4681,23 @@ object Types extends TypeUtils {
46814681 * Anything else should have already been reduced in `appliedTo` by the TypeAssigner.
46824682 * May reduce several HKTypeLambda applications before the underlying MatchType is reached.
46834683 */
4684- override def underlyingMatchType (using Context ): Type =
4685- if ctx.period != validUnderlyingMatch then
4686- cachedUnderlyingMatch = superType.underlyingMatchType
4687- validUnderlyingMatch = validSuper
4688- cachedUnderlyingMatch
4684+ override def underlyingNormalizable (using Context ): Type =
4685+ if ctx.period != validUnderlyingNormalizable then tycon match
4686+ case tycon : TypeRef if defn.isCompiletimeAppliedType(tycon.symbol) =>
4687+ cachedUnderlyingNormalizable = this
4688+ validUnderlyingNormalizable = ctx.period
4689+ case _ =>
4690+ cachedUnderlyingNormalizable = superType.underlyingNormalizable
4691+ validUnderlyingNormalizable = validSuper
4692+ cachedUnderlyingNormalizable
46894693
46904694 override def tryNormalize (using Context ): Type =
46914695 def tryMatchAlias =
46924696 if isMatchAlias then trace(i " normalize $this" , typr, show = true ):
46934697 if MatchTypeTrace .isRecording then
46944698 MatchTypeTrace .recurseWith(this )(superType.tryNormalize)
46954699 else
4696- underlyingMatchType .tryNormalize
4700+ underlyingNormalizable .tryNormalize
46974701 else NoType
46984702 tryCompiletimeConstantFold.orElse(tryMatchAlias)
46994703
@@ -5267,7 +5271,7 @@ object Types extends TypeUtils {
52675271 def apply (bound : Type , scrutinee : Type , cases : List [Type ])(using Context ): MatchType =
52685272 unique(new CachedMatchType (bound, scrutinee, cases))
52695273
5270- def thatReducesUsingGadt (tp : Type )(using Context ): Boolean = tp.underlyingMatchType match
5274+ def thatReducesUsingGadt (tp : Type )(using Context ): Boolean = tp.underlyingNormalizable match
52715275 case mt : MatchType => mt.reducesUsingGadt
52725276 case _ => false
52735277
0 commit comments