Skip to content

Commit 8d65f19

Browse files
committed
Also consider non-final term members with self type refinements
Also consider non-final term members with self type refinements for infoDependsOnPrefix
1 parent c830ad2 commit 8d65f19

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

+17-10
Original file line numberDiff line numberDiff line change
@@ -2501,20 +2501,24 @@ object Types {
25012501

25022502
/** A reference with the initial symbol in `symd` has an info that
25032503
* might depend on the given prefix.
2504-
* Note: If T is an abstract type in trait or class C, its info depends
2505-
* even on C.this if class C has a self type that refines the info of T.
2506-
* We should also treat term members in this way.
2504+
* Note: If M is an abstract type or non-final term member in trait or class C,
2505+
* its info depends even on C.this if class C has a self type that refines
2506+
* the info of M.
25072507
*/
25082508
private def infoDependsOnPrefix(symd: SymDenotation, prefix: Type)(using Context): Boolean =
25092509

25102510
def refines(tp: Type, name: Name): Boolean = tp match
2511-
case AndType(tp1, tp2) => refines(tp1, name) || refines(tp2, name)
2512-
case RefinedType(parent, rname, _) => rname == name || refines(parent, name)
2511+
case AndType(tp1, tp2) =>
2512+
refines(tp1, name) || refines(tp2, name)
2513+
case RefinedType(parent, rname, _) =>
2514+
rname == name || refines(parent, name)
25132515
case tp: ClassInfo =>
2514-
val other = tp.cls.infoOrCompleter.nonPrivateMember(name)
2515-
other.exists && other.symbol != symd.symbol
2516-
case tp: TypeProxy => refines(tp.underlying, name)
2517-
case _ => false
2516+
val otherd = tp.cls.nonPrivateMembersNamed(name)
2517+
otherd.exists && !otherd.containsSym(symd.symbol)
2518+
case tp: TypeProxy =>
2519+
refines(tp.underlying, name)
2520+
case _ =>
2521+
false
25182522

25192523
def givenSelfTypeOrCompleter(cls: Symbol) = cls.infoOrCompleter match
25202524
case cinfo: ClassInfo =>
@@ -2526,7 +2530,10 @@ object Types {
25262530
symd.maybeOwner.membersNeedAsSeenFrom(prefix) && !symd.is(NonMember)
25272531
|| prefix.match
25282532
case prefix: Types.ThisType =>
2529-
symd.isAbstractType
2533+
(symd.isAbstractType
2534+
|| symd.isTerm
2535+
&& !symd.flagsUNSAFE.isOneOf(Module | Final | Param)
2536+
&& !symd.maybeOwner.isEffectivelyFinal)
25302537
&& prefix.sameThis(symd.maybeOwner.thisType)
25312538
&& refines(givenSelfTypeOrCompleter(prefix.cls), symd.name)
25322539
case _ => false

0 commit comments

Comments
 (0)