@@ -1471,48 +1471,48 @@ object Types extends TypeUtils {
1471
1471
case Atoms .Unknown => Atoms .Unknown
1472
1472
case _ => Atoms .Unknown
1473
1473
1474
- private def dealias1 ( keep : AnnotatedType => Context ?=> Boolean , keepOpaques : Boolean )(using Context ): Type = this match {
1474
+ def dealias ( keeps : Keeps )(using Context ): Type = this match
1475
1475
case tp : TypeRef =>
1476
- if ( tp.symbol.isClass) tp
1477
- else tp.info match {
1478
- case TypeAlias (alias) if ! (keepOpaques && tp.symbol.is(Opaque ) ) =>
1479
- alias.dealias1(keep, keepOpaques )
1476
+ if tp.symbol.isClass then tp
1477
+ else tp.info match
1478
+ case TypeAlias (alias) if (keeps & KeepOpaques ) == 0 || ! tp.symbol.is(Opaque ) =>
1479
+ alias.dealias(keeps )
1480
1480
case _ => tp
1481
- }
1482
1481
case app @ AppliedType (tycon, _) =>
1483
- val tycon1 = tycon.dealias1(keep, keepOpaques )
1484
- if ( tycon1 ne tycon) app.superType.dealias1(keep, keepOpaques )
1482
+ val tycon1 = tycon.dealias(keeps )
1483
+ if tycon1 ne tycon then app.superType.dealias(keeps )
1485
1484
else this
1486
- case tp : TypeVar =>
1485
+ case tp : TypeVar if (keeps & KeepTypeVars ) == 0 =>
1487
1486
val tp1 = tp.instanceOpt
1488
- if ( tp1.exists) tp1.dealias1(keep, keepOpaques ) else tp
1487
+ if tp1.exists then tp1.dealias(keeps ) else tp
1489
1488
case tp : AnnotatedType =>
1490
- val parent1 = tp.parent.dealias1(keep, keepOpaques)
1491
- if keep(tp) then tp.derivedAnnotatedType(parent1, tp.annot)
1489
+ val parent1 = tp.parent.dealias(keeps)
1490
+ if (keeps & KeepAnnots ) != 0
1491
+ || (keeps & KeepRefiningAnnots ) != 0 && tp.isRefining
1492
+ then tp.derivedAnnotatedType(parent1, tp.annot)
1492
1493
else tp match
1493
1494
case tp @ CapturingType (parent, refs) =>
1494
1495
tp.derivedCapturingType(parent1, refs)
1495
1496
case _ =>
1496
1497
parent1
1497
1498
case tp : LazyRef =>
1498
- tp.ref.dealias1(keep, keepOpaques )
1499
+ tp.ref.dealias(keeps )
1499
1500
case _ => this
1500
- }
1501
1501
1502
1502
/** Follow aliases and dereference LazyRefs, annotated types and instantiated
1503
1503
* TypeVars until type is no longer alias type, annotated type, LazyRef,
1504
1504
* or instantiated type variable.
1505
1505
*/
1506
- final def dealias (using Context ): Type = dealias1(keepNever, keepOpaques = false )
1506
+ final def dealias (using Context ): Type = dealias( KeepNothing )
1507
1507
1508
1508
/** Follow aliases and dereference LazyRefs and instantiated TypeVars until type
1509
1509
* is no longer alias type, LazyRef, or instantiated type variable.
1510
1510
* Goes through annotated types and rewraps annotations on the result.
1511
1511
*/
1512
- final def dealiasKeepAnnots (using Context ): Type = dealias1(keepAlways, keepOpaques = false )
1512
+ final def dealiasKeepAnnots (using Context ): Type = dealias( KeepAnnots )
1513
1513
1514
1514
/** Like `dealiasKeepAnnots`, but keeps only refining annotations */
1515
- final def dealiasKeepRefiningAnnots (using Context ): Type = dealias1(keepIfRefining, keepOpaques = false )
1515
+ final def dealiasKeepRefiningAnnots (using Context ): Type = dealias( KeepRefiningAnnots )
1516
1516
1517
1517
/** Like dealias, but does not follow aliases if symbol is Opaque. This is
1518
1518
* necessary if we want to look at the info of a symbol containing opaque
@@ -1530,13 +1530,13 @@ object Types extends TypeUtils {
1530
1530
* Here, we dealias symbol infos at the start of capture checking in operation `fluidify`.
1531
1531
* We have to be careful not to accidentally reveal opaque aliases when doing so.
1532
1532
*/
1533
- final def dealiasKeepOpaques (using Context ): Type = dealias1(keepNever, keepOpaques = true )
1533
+ final def dealiasKeepOpaques (using Context ): Type = dealias( KeepOpaques )
1534
1534
1535
1535
/** Like dealiasKeepAnnots, but does not follow opaque aliases. See `dealiasKeepOpaques`
1536
1536
* for why this is sometimes necessary.
1537
1537
*/
1538
1538
final def dealiasKeepAnnotsAndOpaques (using Context ): Type =
1539
- dealias1(keepAlways, keepOpaques = true )
1539
+ dealias( KeepAnnots | KeepOpaques )
1540
1540
1541
1541
/** Approximate this type with a type that does not contain skolem types. */
1542
1542
final def deskolemized (using Context ): Type =
@@ -1568,19 +1568,18 @@ object Types extends TypeUtils {
1568
1568
case tp : AppliedType => tp.underlyingNormalizable
1569
1569
case _ => NoType
1570
1570
1571
- private def widenDealias1 (keep : AnnotatedType => Context ?=> Boolean )(using Context ): Type = {
1572
- val res = this .widen.dealias1(keep, keepOpaques = false )
1573
- if (res eq this ) res else res.widenDealias1(keep)
1574
- }
1571
+ private def widenDealias (keeps : Keeps )(using Context ): Type =
1572
+ val tp1 = widen.dealias(keeps)
1573
+ if tp1 eq this then this else tp1.widenDealias(keeps)
1575
1574
1576
1575
/** Perform successive widenings and dealiasings until none can be applied anymore */
1577
- final def widenDealias (using Context ): Type = widenDealias1(keepNever )
1576
+ final def widenDealias (using Context ): Type = widenDealias( KeepNothing )
1578
1577
1579
1578
/** Perform successive widenings and dealiasings while rewrapping annotations, until none can be applied anymore */
1580
- final def widenDealiasKeepAnnots (using Context ): Type = widenDealias1(keepAlways )
1579
+ final def widenDealiasKeepAnnots (using Context ): Type = widenDealias( KeepAnnots )
1581
1580
1582
1581
/** Perform successive widenings and dealiasings while rewrapping refining annotations, until none can be applied anymore */
1583
- final def widenDealiasKeepRefiningAnnots (using Context ): Type = widenDealias1(keepIfRefining )
1582
+ final def widenDealiasKeepRefiningAnnots (using Context ): Type = widenDealias( KeepRefiningAnnots )
1584
1583
1585
1584
/** Widen from constant type to its underlying non-constant
1586
1585
* base type.
@@ -7027,6 +7026,16 @@ object Types extends TypeUtils {
7027
7026
def isStable = true
7028
7027
}
7029
7028
7029
+ // ----- Dealias keep flags --------------------------------------------
7030
+
7031
+ private type Keeps = Int
7032
+
7033
+ private val KeepNothing = 0
7034
+ private val KeepAnnots = 1
7035
+ private val KeepRefiningAnnots = 2
7036
+ private val KeepOpaques = 4
7037
+ private val KeepTypeVars = 8
7038
+
7030
7039
// ----- Debug ---------------------------------------------------------
7031
7040
7032
7041
@ sharable var debugTrace : Boolean = false
0 commit comments