Skip to content

Commit 9a6a4e8

Browse files
committed
More careful with lookupRefined
Avoid to reduce projections `A{ ... }#T` to aliases if the alias would refer to abstract members of the refinement type.
1 parent 8db6b3e commit 9a6a4e8

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

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

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,21 @@ object Types {
164164
case _ => false
165165
}
166166

167+
/** Is this type a transitive refinement of the given type or class symbol?
168+
* This is true if the type consists of 0 or more refinements or other
169+
* non-singleton proxies that lead to the `prefix` type, or, if
170+
* `prefix` is a class symbol, lead to an instance type of this class.
171+
*/
172+
def refines(prefix: AnyRef /* RefinedType | ClassSymbol */)(implicit ctx: Context): Boolean =
173+
(this eq prefix) || {
174+
this match {
175+
case base: ClassInfo => base.cls eq prefix
176+
case base: SingletonType => false
177+
case base: TypeProxy => base.underlying refines prefix
178+
case _ => false
179+
}
180+
}
181+
167182
// ----- Higher-order combinators -----------------------------------
168183

169184
/** Returns true if there is a part of this type that satisfies predicate `p`.
@@ -635,11 +650,25 @@ object Types {
635650
*/
636651
def lookupRefined(name: Name)(implicit ctx: Context): Type = stripTypeVar match {
637652
case pre: RefinedType =>
638-
if (pre.refinedName ne name) pre.parent.lookupRefined(name)
653+
def dependsOnThis(tp: Type): Boolean = tp match {
654+
case tp @ TypeRef(RefinedThis(rt), _) if rt refines pre =>
655+
tp.info match {
656+
case TypeBounds(lo, hi) if lo eq hi => dependsOnThis(hi)
657+
case _ => true
658+
}
659+
case RefinedThis(rt) =>
660+
rt refines pre
661+
case _ => false
662+
}
663+
if (pre.refinedName ne name)
664+
pre.parent.lookupRefined(name)
639665
else pre.refinedInfo match {
640-
case TypeBounds(lo, hi) /*if lo eq hi*/ => hi
666+
case TypeBounds(lo, hi) if lo eq hi =>
667+
if (hi.existsPart(dependsOnThis)) NoType else hi
641668
case _ => NoType
642669
}
670+
case RefinedThis(rt) =>
671+
rt.lookupRefined(name)
643672
case pre: WildcardType =>
644673
WildcardType
645674
case _ =>

0 commit comments

Comments
 (0)