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