@@ -769,7 +769,7 @@ object Types {
769
769
tycon.derivedLambdaAbstraction(tycon.paramNames, tycon.paramInfos, info).appliedTo(tp.args))
770
770
771
771
def goThis (tp : ThisType ) =
772
- val underlying = tp.underlying
772
+ val underlying = tp.underlying(withOpaque = true )
773
773
val d = go(underlying)
774
774
if d.exists then
775
775
if underlying.isInstanceOf [AndType ] then
@@ -2694,10 +2694,14 @@ object Types {
2694
2694
case _ if ctx.mode.is(Mode .Interactive ) => defn.AnyClass // was observed to happen in IDE mode
2695
2695
}
2696
2696
2697
- override def underlying (using Context ): Type =
2697
+ override def underlying (using Context ): Type = underlying(withOpaque = false )
2698
+
2699
+ final def underlying (withOpaque : Boolean )(using Context ): Type =
2698
2700
if (ctx.erasedTypes) tref
2699
2701
else cls.info match {
2700
- case cinfo : ClassInfo => cinfo.selfType
2702
+ case cinfo : ClassInfo =>
2703
+ if withOpaque then cinfo.selfType
2704
+ else cinfo.selfTypeWithoutOpaque
2701
2705
case _ : ErrorType | NoType if ctx.mode.is(Mode .Interactive ) => cls.info
2702
2706
// can happen in IDE if `cls` is stale
2703
2707
}
@@ -4548,6 +4552,7 @@ object Types {
4548
4552
4549
4553
private var selfTypeCache : Type = null
4550
4554
private var appliedRefCache : Type = null
4555
+ private var selfTypeWithoutOpaqueCache : Type = null
4551
4556
4552
4557
/** The self type of a class is the conjunction of
4553
4558
* - the explicit self type if given (or the info of a given self symbol), and
@@ -4566,6 +4571,23 @@ object Types {
4566
4571
selfTypeCache
4567
4572
}
4568
4573
4574
+ /** The self type without opaque members refinements */
4575
+ def selfTypeWithoutOpaque (using Context ): Type = {
4576
+ def dropRefinement (tp : Type ): Type = tp match
4577
+ case RefinedType (parent, _, _ : TypeAlias ) =>
4578
+ // TODO: maybe strengthen the check for Opaque flag
4579
+ parent
4580
+ case AndType (tp1, tp2) =>
4581
+ AndType (dropRefinement(tp1), dropRefinement(tp2))
4582
+ case _ =>
4583
+ tp
4584
+ end dropRefinement
4585
+
4586
+ if selfTypeWithoutOpaqueCache == null then
4587
+ selfTypeWithoutOpaqueCache = dropRefinement(selfType)
4588
+ selfTypeWithoutOpaqueCache
4589
+ }
4590
+
4569
4591
def appliedRef (using Context ): Type = {
4570
4592
if (appliedRefCache == null )
4571
4593
appliedRefCache =
0 commit comments