Skip to content

Commit 9c46f72

Browse files
committed
Fix findMember of SuperType
It used to return the joint denotation, but the correct answer is the denotation of the symbol in the joint denotation as seen from the super prefix.
1 parent 347a3aa commit 9c46f72

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

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

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ object Types {
384384

385385
/** The base classes of this type as determined by ClassDenotation
386386
* in linearization order, with the class itself as first element.
387-
* For AndTypes/OrTypes, the union/intersection of the operands' baseclasses.
387+
* For AndTypes/OrTypes, the merge/intersection of the operands' baseclasses.
388388
* Inherited by all type proxies. `Nil` for all other types.
389389
*/
390390
final def baseClasses(implicit ctx: Context): List[ClassSymbol] = track("baseClasses") {
@@ -475,22 +475,24 @@ object Types {
475475
*/
476476
final def findMember(name: Name, pre: Type, excluded: FlagSet)(implicit ctx: Context): Denotation = {
477477
@tailrec def go(tp: Type): Denotation = tp match {
478-
case tp: RefinedType =>
479-
if (name eq tp.refinedName) goRefined(tp) else go(tp.parent)
480-
case tp: ThisType =>
481-
goThis(tp)
482-
case tp: TypeRef =>
483-
tp.denot.findMember(name, pre, excluded)
484478
case tp: TermRef =>
485479
go (tp.underlying match {
486480
case mt: MethodType
487481
if mt.paramInfos.isEmpty && (tp.symbol is Stable) => mt.resultType
488482
case tp1 => tp1
489483
})
490-
case tp: TypeParamRef =>
491-
goParam(tp)
484+
case tp: TypeRef =>
485+
tp.denot.findMember(name, pre, excluded)
486+
case tp: ThisType =>
487+
goThis(tp)
488+
case tp: RefinedType =>
489+
if (name eq tp.refinedName) goRefined(tp) else go(tp.parent)
492490
case tp: RecType =>
493491
goRec(tp)
492+
case tp: TypeParamRef =>
493+
goParam(tp)
494+
case tp: SuperType =>
495+
goSuper(tp)
494496
case tp: HKApply =>
495497
goApply(tp)
496498
case tp: TypeProxy =>
@@ -614,6 +616,12 @@ object Types {
614616
go(next)
615617
}
616618
}
619+
def goSuper(tp: SuperType) = go(tp.underlying) match {
620+
case d: JointRefDenotation =>
621+
typr.println(i"redirecting super.$name from $tp to ${d.symbol.showLocated}")
622+
new UniqueRefDenotation(d.symbol, tp.memberInfo(d.symbol), d.validFor)
623+
case d => d
624+
}
617625
def goAnd(l: Type, r: Type) = {
618626
go(l) & (go(r), pre, safeIntersection = ctx.pendingMemberSearches.contains(name))
619627
}

0 commit comments

Comments
 (0)