@@ -452,13 +452,18 @@ object Types extends TypeUtils {
452
452
/** Is this a MethodType for which the parameters will not be used? */
453
453
def hasErasedParams (using Context ): Boolean = false
454
454
455
- /** Is this a match type or a higher-kinded abstraction of one?
456
- */
457
- def isMatch (using Context ): Boolean = underlyingMatchType.exists
455
+ /** Is this a match type or a higher-kinded abstraction of one? */
456
+ def isMatch (using Context ): Boolean = stripped match
457
+ case tp : MatchType => true
458
+ case tp : HKTypeLambda => tp.resType.isMatch
459
+ case _ => false
460
+
461
+ /** Does this application expand to a match type? */
462
+ def isMatchAlias (using Context ): Boolean = underlyingNormalizable.isMatch
458
463
459
- def underlyingMatchType (using Context ): Type = stripped match
464
+ def underlyingNormalizable (using Context ): Type = stripped match
460
465
case tp : MatchType => tp
461
- case tp : AppliedType => tp.underlyingMatchType
466
+ case tp : AppliedType => tp.underlyingNormalizable
462
467
case _ => NoType
463
468
464
469
/** Is this a higher-kinded type lambda with given parameter variances?
@@ -4453,8 +4458,8 @@ object Types extends TypeUtils {
4453
4458
private var myEvalRunId : RunId = NoRunId
4454
4459
private var myEvalued : Type = uninitialized
4455
4460
4456
- private var validUnderlyingMatch : Period = Nowhere
4457
- private var cachedUnderlyingMatch : Type = uninitialized
4461
+ private var validUnderlyingNormalizable : Period = Nowhere
4462
+ private var cachedUnderlyingNormalizable : Type = uninitialized
4458
4463
4459
4464
def isGround (acc : TypeAccumulator [Boolean ])(using Context ): Boolean =
4460
4465
if myGround == 0 then myGround = if acc.foldOver(true , this ) then 1 else - 1
@@ -4516,30 +4521,26 @@ object Types extends TypeUtils {
4516
4521
* Anything else should have already been reduced in `appliedTo` by the TypeAssigner.
4517
4522
* May reduce several HKTypeLambda applications before the underlying MatchType is reached.
4518
4523
*/
4519
- override def underlyingMatchType (using Context ): Type =
4520
- if ctx.period != validUnderlyingMatch then
4521
- cachedUnderlyingMatch = superType.underlyingMatchType
4522
- validUnderlyingMatch = validSuper
4523
- cachedUnderlyingMatch
4524
+ override def underlyingNormalizable (using Context ): Type =
4525
+ if ctx.period != validUnderlyingNormalizable then tycon match
4526
+ case tycon : TypeRef if defn.isCompiletimeAppliedType(tycon.symbol) =>
4527
+ cachedUnderlyingNormalizable = this
4528
+ validUnderlyingNormalizable = ctx.period
4529
+ case _ =>
4530
+ cachedUnderlyingNormalizable = superType.underlyingNormalizable
4531
+ validUnderlyingNormalizable = validSuper
4532
+ cachedUnderlyingNormalizable
4524
4533
4525
4534
override def tryNormalize (using Context ): Type =
4526
4535
def tryMatchAlias =
4527
4536
if isMatchAlias then trace(i " normalize $this" , typr, show = true ):
4528
4537
if MatchTypeTrace .isRecording then
4529
4538
MatchTypeTrace .recurseWith(this )(superType.tryNormalize)
4530
4539
else
4531
- underlyingMatchType .tryNormalize
4540
+ underlyingNormalizable .tryNormalize
4532
4541
else NoType
4533
4542
tryCompiletimeConstantFold.orElse(tryMatchAlias)
4534
4543
4535
- /** Does this application expand to a match type? */
4536
- def isMatchAlias (using Context ): Boolean = tycon.stripTypeVar match
4537
- case tycon : TypeRef =>
4538
- tycon.info match
4539
- case _ : MatchAlias => true
4540
- case _ => false
4541
- case _ => false
4542
-
4543
4544
/** Is this an unreducible application to wildcard arguments?
4544
4545
* This is the case if tycon is higher-kinded. This means
4545
4546
* it is a subtype of a hk-lambda, but not a match alias.
@@ -5041,10 +5042,9 @@ object Types extends TypeUtils {
5041
5042
def apply (bound : Type , scrutinee : Type , cases : List [Type ])(using Context ): MatchType =
5042
5043
unique(new CachedMatchType (bound, scrutinee, cases))
5043
5044
5044
- def thatReducesUsingGadt (tp : Type )(using Context ): Boolean = tp match
5045
- case MatchType .InDisguise (mt) => mt.reducesUsingGadt
5046
- case mt : MatchType => mt.reducesUsingGadt
5047
- case _ => false
5045
+ def thatReducesUsingGadt (tp : Type )(using Context ): Boolean = tp.underlyingNormalizable match
5046
+ case mt : MatchType => mt.reducesUsingGadt
5047
+ case _ => false
5048
5048
5049
5049
/** Extractor for match types hidden behind an AppliedType/MatchAlias. */
5050
5050
object InDisguise :
0 commit comments