@@ -1642,17 +1642,19 @@ object Types extends TypeUtils {
1642
1642
*
1643
1643
* P { ... type T = / += / -= U ... } # T
1644
1644
*
1645
- * to just U. Does not perform the reduction if the resulting type would contain
1646
- * a reference to the "this" of the current refined type, except in the following situation
1645
+ * to just U. Analogously, `P { val x: S} # x` is reduced tp `S` is `S`
1646
+ * is a singleton type.
1647
1647
*
1648
- * (1) The "this" reference can be avoided by following an alias. Example:
1648
+ * Does not perform the reduction if the resulting type would contain
1649
+ * a reference to the "this" of the current refined type, except if the "this"
1650
+ * reference can be avoided by following an alias. Example:
1649
1651
*
1650
1652
* P { type T = String, type R = P{...}.T } # R --> String
1651
1653
*
1652
1654
* (*) normalizes means: follow instantiated typevars and aliases.
1653
1655
*/
1654
- def lookupRefined (name : Name )(using Context ): Type = {
1655
- @ tailrec def loop (pre : Type ): Type = pre.stripTypeVar match {
1656
+ def lookupRefined (name : Name )(using Context ): Type =
1657
+ @ tailrec def loop (pre : Type ): Type = pre match
1656
1658
case pre : RefinedType =>
1657
1659
pre.refinedInfo match {
1658
1660
case tp : AliasingBounds =>
@@ -1675,12 +1677,13 @@ object Types extends TypeUtils {
1675
1677
case TypeAlias (alias) => loop(alias)
1676
1678
case _ => NoType
1677
1679
}
1680
+ case pre : (TypeVar | AnnotatedType ) =>
1681
+ loop(pre.underlying)
1678
1682
case _ =>
1679
1683
NoType
1680
- }
1681
1684
1682
1685
loop(this )
1683
- }
1686
+ end lookupRefined
1684
1687
1685
1688
/** The type <this . name> , reduced if possible */
1686
1689
def select (name : Name )(using Context ): Type =
@@ -2820,35 +2823,30 @@ object Types extends TypeUtils {
2820
2823
def derivedSelect (prefix : Type )(using Context ): Type =
2821
2824
if prefix eq this .prefix then this
2822
2825
else if prefix.isExactlyNothing then prefix
2823
- else {
2824
- val res =
2825
- if ( isType && currentValidSymbol.isAllOf(ClassTypeParam )) argForParam(prefix)
2826
+ else
2827
+ val reduced =
2828
+ if isType && currentValidSymbol.isAllOf(ClassTypeParam ) then argForParam(prefix)
2826
2829
else prefix.lookupRefined(name)
2827
- if (res.exists) return res
2828
- if (isType) {
2829
- if (Config .splitProjections)
2830
- prefix match {
2831
- case prefix : AndType =>
2832
- def isMissing (tp : Type ) = tp match {
2833
- case tp : TypeRef => ! tp.info.exists
2834
- case _ => false
2835
- }
2836
- val derived1 = derivedSelect(prefix.tp1)
2837
- val derived2 = derivedSelect(prefix.tp2)
2838
- return (
2839
- if (isMissing(derived1)) derived2
2840
- else if (isMissing(derived2)) derived1
2841
- else prefix.derivedAndType(derived1, derived2))
2842
- case prefix : OrType =>
2843
- val derived1 = derivedSelect(prefix.tp1)
2844
- val derived2 = derivedSelect(prefix.tp2)
2845
- return prefix.derivedOrType(derived1, derived2)
2846
- case _ =>
2847
- }
2848
- }
2849
- if (prefix.isInstanceOf [WildcardType ]) WildcardType .sameKindAs(this )
2830
+ if reduced.exists then return reduced
2831
+ if Config .splitProjections && isType then
2832
+ prefix match
2833
+ case prefix : AndType =>
2834
+ def isMissing (tp : Type ) = tp match
2835
+ case tp : TypeRef => ! tp.info.exists
2836
+ case _ => false
2837
+ val derived1 = derivedSelect(prefix.tp1)
2838
+ val derived2 = derivedSelect(prefix.tp2)
2839
+ return
2840
+ if isMissing(derived1) then derived2
2841
+ else if isMissing(derived2) then derived1
2842
+ else prefix.derivedAndType(derived1, derived2)
2843
+ case prefix : OrType =>
2844
+ val derived1 = derivedSelect(prefix.tp1)
2845
+ val derived2 = derivedSelect(prefix.tp2)
2846
+ return prefix.derivedOrType(derived1, derived2)
2847
+ case _ =>
2848
+ if prefix.isInstanceOf [WildcardType ] then WildcardType .sameKindAs(this )
2850
2849
else withPrefix(prefix)
2851
- }
2852
2850
2853
2851
/** A reference like this one, but with the given symbol, if it exists */
2854
2852
private def withSym (sym : Symbol )(using Context ): ThisType =
0 commit comments