@@ -164,6 +164,21 @@ object Types {
164
164
case _ => false
165
165
}
166
166
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
+
167
182
// ----- Higher-order combinators -----------------------------------
168
183
169
184
/** Returns true if there is a part of this type that satisfies predicate `p`.
@@ -635,11 +650,25 @@ object Types {
635
650
*/
636
651
def lookupRefined (name : Name )(implicit ctx : Context ): Type = stripTypeVar match {
637
652
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)
639
665
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
641
668
case _ => NoType
642
669
}
670
+ case RefinedThis (rt) =>
671
+ rt.lookupRefined(name)
643
672
case pre : WildcardType =>
644
673
WildcardType
645
674
case _ =>
0 commit comments