@@ -702,9 +702,22 @@ object Types {
702702 go(tycon.resType).mapInfo(info =>
703703 tycon.derivedLambdaAbstraction(tycon.paramNames, tycon.paramInfos, info).appliedTo(tp.args))
704704
705- def goThis (tp : ThisType ) = {
706- val d = go(tp.underlying)
707- if (d.exists) d
705+ def goThis (tp : ThisType ) =
706+ val underlying = tp.underlying
707+ val d = go(underlying)
708+ if d.exists then
709+ if underlying.isInstanceOf [AndType ] then
710+ // The underlying type of `this` is specified in a self type clause.
711+ // In this case we need to exclude all private members from `d` which are
712+ // not defined in the class of the `this` type. We could do this test
713+ // always, but the restriction to test only if `underlying` is an AndType
714+ // is made to save execution time in the common case. See i9844.scala for test cases.
715+ def qualifies (sd : SingleDenotation ) =
716+ ! sd.symbol.is(Private ) || sd.symbol.owner == tp.cls
717+ d match
718+ case d : SingleDenotation => if qualifies(d) then d else NoDenotation
719+ case d => d.filterWithPredicate(qualifies)
720+ else d
708721 else
709722 // There is a special case to handle:
710723 // trait Super { this: Sub => private class Inner {} println(this.Inner) }
@@ -716,7 +729,6 @@ object Types {
716729 // As an example of this in the wild, see
717730 // loadClassWithPrivateInnerAndSubSelf in ShowClassTests
718731 go(tp.cls.typeRef) orElse d
719- }
720732
721733 def goParam (tp : TypeParamRef ) = {
722734 val next = tp.underlying
0 commit comments