@@ -1363,42 +1363,49 @@ object Types {
1363
1363
case Atoms .Unknown => Atoms .Unknown
1364
1364
case _ => Atoms .Unknown
1365
1365
1366
- private def dealias1 (keep : AnnotatedType => Context ?=> Boolean )(using Context ): Type = this match {
1366
+ private def dealias1 (keep : AnnotatedType => Context ?=> Boolean , keepOpaques : Boolean )(using Context ): Type = this match {
1367
1367
case tp : TypeRef =>
1368
1368
if (tp.symbol.isClass) tp
1369
1369
else tp.info match {
1370
- case TypeAlias (alias) => alias.dealias1(keep)
1370
+ case TypeAlias (alias) if ! (keepOpaques && tp.symbol.is(Opaque )) =>
1371
+ alias.dealias1(keep, keepOpaques)
1371
1372
case _ => tp
1372
1373
}
1373
1374
case app @ AppliedType (tycon, _) =>
1374
- val tycon1 = tycon.dealias1(keep)
1375
- if (tycon1 ne tycon) app.superType.dealias1(keep)
1375
+ val tycon1 = tycon.dealias1(keep, keepOpaques )
1376
+ if (tycon1 ne tycon) app.superType.dealias1(keep, keepOpaques )
1376
1377
else this
1377
1378
case tp : TypeVar =>
1378
1379
val tp1 = tp.instanceOpt
1379
- if (tp1.exists) tp1.dealias1(keep) else tp
1380
+ if (tp1.exists) tp1.dealias1(keep, keepOpaques ) else tp
1380
1381
case tp : AnnotatedType =>
1381
- val tp1 = tp.parent.dealias1(keep)
1382
+ val tp1 = tp.parent.dealias1(keep, keepOpaques )
1382
1383
if keep(tp) then tp.derivedAnnotatedType(tp1, tp.annot) else tp1
1383
1384
case tp : LazyRef =>
1384
- tp.ref.dealias1(keep)
1385
+ tp.ref.dealias1(keep, keepOpaques )
1385
1386
case _ => this
1386
1387
}
1387
1388
1388
1389
/** Follow aliases and dereferences LazyRefs, annotated types and instantiated
1389
1390
* TypeVars until type is no longer alias type, annotated type, LazyRef,
1390
1391
* or instantiated type variable.
1391
1392
*/
1392
- final def dealias (using Context ): Type = dealias1(keepNever)
1393
+ final def dealias (using Context ): Type = dealias1(keepNever, keepOpaques = false )
1393
1394
1394
1395
/** Follow aliases and dereferences LazyRefs and instantiated TypeVars until type
1395
1396
* is no longer alias type, LazyRef, or instantiated type variable.
1396
1397
* Goes through annotated types and rewraps annotations on the result.
1397
1398
*/
1398
- final def dealiasKeepAnnots (using Context ): Type = dealias1(keepAlways)
1399
+ final def dealiasKeepAnnots (using Context ): Type = dealias1(keepAlways, keepOpaques = false )
1399
1400
1400
1401
/** Like `dealiasKeepAnnots`, but keeps only refining annotations */
1401
- final def dealiasKeepRefiningAnnots (using Context ): Type = dealias1(keepIfRefining)
1402
+ final def dealiasKeepRefiningAnnots (using Context ): Type = dealias1(keepIfRefining, keepOpaques = false )
1403
+
1404
+ /** Follow non-opaque aliases and dereferences LazyRefs, annotated types and instantiated
1405
+ * TypeVars until type is no longer alias type, annotated type, LazyRef,
1406
+ * or instantiated type variable.
1407
+ */
1408
+ final def dealiasKeepOpaques (using Context ): Type = dealias1(keepNever, keepOpaques = true )
1402
1409
1403
1410
/** Approximate this type with a type that does not contain skolem types. */
1404
1411
final def deskolemized (using Context ): Type =
@@ -1426,7 +1433,7 @@ object Types {
1426
1433
def tryNormalize (using Context ): Type = NoType
1427
1434
1428
1435
private def widenDealias1 (keep : AnnotatedType => Context ?=> Boolean )(using Context ): Type = {
1429
- val res = this .widen.dealias1(keep)
1436
+ val res = this .widen.dealias1(keep, keepOpaques = false )
1430
1437
if (res eq this ) res else res.widenDealias1(keep)
1431
1438
}
1432
1439
0 commit comments