Skip to content

Commit 8711886

Browse files
committed
Refactoring of derivedSelect
If splitProjections is set, it is more efficient that way.
1 parent d362455 commit 8711886

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,19 +1536,24 @@ object Types {
15361536
/** A selection of the same kind, but with potentially a differet prefix.
15371537
* The following normalizations are performed for type selections T#A:
15381538
*
1539-
* 1. If Config.splitProjections is true:
1539+
* T#A --> B if A is bound to an alias `= B` in T
15401540
*
1541-
* (S & T)#A --> S#A & T#A
1541+
* (S & T)#A --> S#A if T does not have a member namd A
1542+
* --> T#A if S does not have a member namd A
1543+
* --> S#A & T#A otherwise
15421544
* (S | T)#A --> S#A | T#A
1543-
*
1544-
* 2. If A is bound to an alias `= B` in T
1545-
*
1546-
* T#A --> B
15471545
*/
15481546
def derivedSelect(prefix: Type)(implicit ctx: Context): Type =
15491547
if (prefix eq this.prefix) this
1550-
else {
1551-
if (Config.splitProjections && isType)
1548+
else if (isType) {
1549+
val res = prefix.lookupRefined(name)
1550+
if (res.exists) res
1551+
else if (name == tpnme.hkApply && prefix.classNotLambda)
1552+
// After substitution we might end up with a type like
1553+
// `C { type hk$0 = T0; ...; type hk$n = Tn } # $Apply`
1554+
// where C is a class. In that case we eta expand `C`.
1555+
derivedSelect(prefix.EtaExpandCore(this.prefix.typeConstructor.typeParams))
1556+
else if (Config.splitProjections)
15521557
prefix match {
15531558
case prefix: AndType =>
15541559
def isMissing(tp: Type) = tp match {
@@ -1566,16 +1571,11 @@ object Types {
15661571
val derived2 = derivedSelect(prefix.tp2)
15671572
return prefix.derivedOrType(derived1, derived2)
15681573
case _ =>
1574+
newLikeThis(prefix)
15691575
}
1570-
val res = prefix.lookupRefined(name)
1571-
if (res.exists) res
1572-
else if (name == tpnme.hkApply && prefix.classNotLambda) {
1573-
// After substitution we might end up with a type like
1574-
// `C { type hk$0 = T0; ...; type hk$n = Tn } # $Apply`
1575-
// where C is a class. In that case we eta expand `C`.
1576-
derivedSelect(prefix.EtaExpandCore(this.prefix.typeConstructor.typeParams))
1577-
} else newLikeThis(prefix)
1576+
else newLikeThis(prefix)
15781577
}
1578+
else newLikeThis(prefix)
15791579

15801580
/** Create a NamedType of the same kind as this type, but with a new prefix.
15811581
*/
@@ -2804,7 +2804,7 @@ object Types {
28042804
}
28052805

28062806
override def toString =
2807-
if (lo eq hi) s"TypeAlias($lo)" else s"TypeBounds($lo, $hi)"
2807+
if (lo eq hi) s"TypeAlias($lo, $variance)" else s"TypeBounds($lo, $hi)"
28082808
}
28092809

28102810
class RealTypeBounds(lo: Type, hi: Type) extends TypeBounds(lo, hi) {

0 commit comments

Comments
 (0)