@@ -1631,17 +1631,19 @@ object Types extends TypeUtils {
1631
1631
*
1632
1632
* P { ... type T = / += / -= U ... } # T
1633
1633
*
1634
- * to just U. Does not perform the reduction if the resulting type would contain
1635
- * a reference to the "this" of the current refined type, except in the following situation
1634
+ * to just U. Analogously, `P { val x: S} # x` is reduced tp `S` is `S`
1635
+ * is a singleton type.
1636
1636
*
1637
- * (1) The "this" reference can be avoided by following an alias. Example:
1637
+ * Does not perform the reduction if the resulting type would contain
1638
+ * a reference to the "this" of the current refined type, except if the "this"
1639
+ * reference can be avoided by following an alias. Example:
1638
1640
*
1639
1641
* P { type T = String, type R = P{...}.T } # R --> String
1640
1642
*
1641
1643
* (*) normalizes means: follow instantiated typevars and aliases.
1642
1644
*/
1643
- def lookupRefined (name : Name )(using Context ): Type = {
1644
- @ tailrec def loop (pre : Type ): Type = pre.stripTypeVar match {
1645
+ def lookupRefined (name : Name )(using Context ): Type =
1646
+ @ tailrec def loop (pre : Type ): Type = pre match
1645
1647
case pre : RefinedType =>
1646
1648
pre.refinedInfo match {
1647
1649
case tp : AliasingBounds =>
@@ -1664,12 +1666,13 @@ object Types extends TypeUtils {
1664
1666
case TypeAlias (alias) => loop(alias)
1665
1667
case _ => NoType
1666
1668
}
1669
+ case pre : (TypeVar | AnnotatedType ) =>
1670
+ loop(pre.underlying)
1667
1671
case _ =>
1668
1672
NoType
1669
- }
1670
1673
1671
1674
loop(this )
1672
- }
1675
+ end lookupRefined
1673
1676
1674
1677
/** The type <this . name> , reduced if possible */
1675
1678
def select (name : Name )(using Context ): Type =
@@ -2809,35 +2812,30 @@ object Types extends TypeUtils {
2809
2812
def derivedSelect (prefix : Type )(using Context ): Type =
2810
2813
if prefix eq this .prefix then this
2811
2814
else if prefix.isExactlyNothing then prefix
2812
- else {
2813
- val res =
2814
- if ( isType && currentValidSymbol.isAllOf(ClassTypeParam )) argForParam(prefix)
2815
+ else
2816
+ val reduced =
2817
+ if isType && currentValidSymbol.isAllOf(ClassTypeParam ) then argForParam(prefix)
2815
2818
else prefix.lookupRefined(name)
2816
- if (res.exists) return res
2817
- if (isType) {
2818
- if (Config .splitProjections)
2819
- prefix match {
2820
- case prefix : AndType =>
2821
- def isMissing (tp : Type ) = tp match {
2822
- case tp : TypeRef => ! tp.info.exists
2823
- case _ => false
2824
- }
2825
- val derived1 = derivedSelect(prefix.tp1)
2826
- val derived2 = derivedSelect(prefix.tp2)
2827
- return (
2828
- if (isMissing(derived1)) derived2
2829
- else if (isMissing(derived2)) derived1
2830
- else prefix.derivedAndType(derived1, derived2))
2831
- case prefix : OrType =>
2832
- val derived1 = derivedSelect(prefix.tp1)
2833
- val derived2 = derivedSelect(prefix.tp2)
2834
- return prefix.derivedOrType(derived1, derived2)
2835
- case _ =>
2836
- }
2837
- }
2838
- if (prefix.isInstanceOf [WildcardType ]) WildcardType .sameKindAs(this )
2819
+ if reduced.exists then return reduced
2820
+ if Config .splitProjections && isType then
2821
+ prefix match
2822
+ case prefix : AndType =>
2823
+ def isMissing (tp : Type ) = tp match
2824
+ case tp : TypeRef => ! tp.info.exists
2825
+ case _ => false
2826
+ val derived1 = derivedSelect(prefix.tp1)
2827
+ val derived2 = derivedSelect(prefix.tp2)
2828
+ return
2829
+ if isMissing(derived1) then derived2
2830
+ else if isMissing(derived2) then derived1
2831
+ else prefix.derivedAndType(derived1, derived2)
2832
+ case prefix : OrType =>
2833
+ val derived1 = derivedSelect(prefix.tp1)
2834
+ val derived2 = derivedSelect(prefix.tp2)
2835
+ return prefix.derivedOrType(derived1, derived2)
2836
+ case _ =>
2837
+ if prefix.isInstanceOf [WildcardType ] then WildcardType .sameKindAs(this )
2839
2838
else withPrefix(prefix)
2840
- }
2841
2839
2842
2840
/** A reference like this one, but with the given symbol, if it exists */
2843
2841
private def withSym (sym : Symbol )(using Context ): ThisType =
0 commit comments