@@ -466,7 +466,7 @@ object Types extends TypeUtils {
466466 case _ => false
467467
468468 /** Does this application expand to a match type? */
469- def isMatchAlias (using Context ): Boolean = underlyingMatchType.exists
469+ def isMatchAlias (using Context ): Boolean = underlyingNormalizable.isMatch
470470
471471 /** Is this a higher-kinded type lambda with given parameter variances?
472472 * These lambdas are used as the RHS of higher-kinded abstract types or
@@ -1519,27 +1519,23 @@ object Types extends TypeUtils {
15191519 }
15201520 deskolemizer(this )
15211521
1522- /** Constant fold applied compiletime operations if possible */
1523- final def compiletimeConstantFolded (using Context ) = this match
1524- case tp : AppliedType => tp.tryCompiletimeConstantFold.orElse(this )
1525- case tp => tp
1526-
15271522 /** The result of normalization, or the type itself if none apply. */
15281523 final def normalized (using Context ): Type = tryNormalize.orElse(this )
15291524
1530- /** If this type has an underlying match type, the result after applying all
1531- * toplevel normalizations, otherwise NoType.
1525+ /** If this type has an underlying match type or applied compiletime.ops,
1526+ * then the result after applying all toplevel normalizations, otherwise NoType.
15321527 */
1533- def tryNormalize (using Context ): Type = underlyingMatchType match
1528+ def tryNormalize (using Context ): Type = underlyingNormalizable match
15341529 case mt : MatchType => mt.reduced.normalized
1530+ case tp : AppliedType => tp.tryCompiletimeConstantFold
15351531 case _ => NoType
15361532
15371533 /** Perform successive dealiasings and beta-reductions of applied types until
15381534 * a match type is reached if any, otherwise NoType.
15391535 */
1540- def underlyingMatchType (using Context ): Type = this .safeDealias.stripLazyRef match
1536+ def underlyingNormalizable (using Context ): Type = this .safeDealias.stripLazyRef match
15411537 case tp : MatchType => tp
1542- case tp : AppliedType => tp.underlyingMatchType
1538+ case tp : AppliedType => tp.underlyingNormalizable
15431539 case _ => NoType
15441540
15451541 private def widenDealias1 (keep : AnnotatedType => Context ?=> Boolean )(using Context ): Type = {
@@ -4586,8 +4582,8 @@ object Types extends TypeUtils {
45864582 private var myEvalRunId : RunId = NoRunId
45874583 private var myEvalued : Type = uninitialized
45884584
4589- private var validUnderlyingMatch : Period = Nowhere
4590- private var cachedUnderlyingMatch : Type = uninitialized
4585+ private var validUnderlyingNormalizable : Period = Nowhere
4586+ private var cachedUnderlyingNormalizable : Type = uninitialized
45914587
45924588 def isGround (acc : TypeAccumulator [Boolean ])(using Context ): Boolean =
45934589 if myGround == 0 then myGround = if acc.foldOver(true , this ) then 1 else - 1
@@ -4649,11 +4645,13 @@ object Types extends TypeUtils {
46494645 * Anything else should have already been reduced in `appliedTo` by the TypeAssigner.
46504646 * May reduce several HKTypeLambda applications before the underlying MatchType is reached.
46514647 */
4652- override def underlyingMatchType (using Context ): Type =
4653- if ctx.period != validUnderlyingMatch then
4654- validUnderlyingMatch = if tycon.isProvisional then Nowhere else ctx.period
4655- cachedUnderlyingMatch = superType.underlyingMatchType
4656- cachedUnderlyingMatch
4648+ override def underlyingNormalizable (using Context ): Type =
4649+ if ctx.period != validUnderlyingNormalizable then
4650+ validUnderlyingNormalizable = if tycon.isProvisional then Nowhere else ctx.period
4651+ cachedUnderlyingNormalizable = tycon match
4652+ case tycon : TypeRef if defn.isCompiletimeAppliedType(tycon.symbol) => this
4653+ case _ => superType.underlyingNormalizable
4654+ cachedUnderlyingNormalizable
46574655
46584656 override def tryNormalize (using Context ): Type =
46594657 if MatchTypeTrace .isRecording && isMatchAlias then
@@ -5153,8 +5151,7 @@ object Types extends TypeUtils {
51535151 myReduced = trace(i " reduce match type $this $hashCode" , matchTypes, show = true ):
51545152 withMode(Mode .Type ):
51555153 TypeComparer .reduceMatchWith: cmp =>
5156- val scrutNormed = scrutinee.normalized.compiletimeConstantFolded
5157- cmp.matchCases(scrutNormed, cases.map(MatchTypeCaseSpec .analyze))
5154+ cmp.matchCases(scrutinee.normalized, cases.map(MatchTypeCaseSpec .analyze))
51585155 catch case ex : Throwable =>
51595156 myReduced = NoType
51605157 handleRecursive(" reduce type " , i " $scrutinee match ... " , ex)
@@ -5188,7 +5185,7 @@ object Types extends TypeUtils {
51885185 def apply (bound : Type , scrutinee : Type , cases : List [Type ])(using Context ): MatchType =
51895186 unique(new CachedMatchType (bound, scrutinee, cases))
51905187
5191- def thatReducesUsingGadt (tp : Type )(using Context ): Boolean = tp.underlyingMatchType match
5188+ def thatReducesUsingGadt (tp : Type )(using Context ): Boolean = tp.underlyingNormalizable match
51925189 case mt : MatchType => mt.reducesUsingGadt
51935190 case _ => false
51945191
0 commit comments