Skip to content

Commit 0a2d995

Browse files
committed
Also reduce term projections
We already reduce `R { type A = T } # A` to `T` in most situations when we create types. We now also reduce `R { val x: S } # x` to `S` if `S` is a singleton type. This will simplify types as we go to more term-dependent typing. As a concrete benefit, it will avoid several test-pickling failures due to pickling differences when using dependent types.
1 parent f95b57c commit 0a2d995

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,6 +1645,8 @@ object Types extends TypeUtils {
16451645
pre.refinedInfo match {
16461646
case tp: AliasingBounds =>
16471647
if (pre.refinedName ne name) loop(pre.parent) else tp.alias
1648+
case tp: SingletonType =>
1649+
if pre.refinedName ne name then loop(pre.parent) else tp
16481650
case _ =>
16491651
loop(pre.parent)
16501652
}
@@ -2676,7 +2678,7 @@ object Types extends TypeUtils {
26762678
* refinement type `T { X = U; ... }`
26772679
*/
26782680
def reduceProjection(using Context): Type =
2679-
if (isType) {
2681+
if (isType || true) {
26802682
val reduced = prefix.lookupRefined(name)
26812683
if (reduced.exists) reduced else this
26822684
}
@@ -2765,14 +2767,14 @@ object Types extends TypeUtils {
27652767
* (S | T)#A --> S#A | T#A
27662768
*/
27672769
def derivedSelect(prefix: Type)(using Context): Type =
2768-
if (prefix eq this.prefix) this
2769-
else if (prefix.isExactlyNothing) prefix
2770+
if prefix eq this.prefix then this
2771+
else if prefix.isExactlyNothing then prefix
27702772
else {
2773+
val res =
2774+
if (isType && currentValidSymbol.isAllOf(ClassTypeParam)) argForParam(prefix)
2775+
else prefix.lookupRefined(name)
2776+
if (res.exists) return res
27712777
if (isType) {
2772-
val res =
2773-
if (currentValidSymbol.isAllOf(ClassTypeParam)) argForParam(prefix)
2774-
else prefix.lookupRefined(name)
2775-
if (res.exists) return res
27762778
if (Config.splitProjections)
27772779
prefix match {
27782780
case prefix: AndType =>
@@ -6563,7 +6565,7 @@ object Types extends TypeUtils {
65636565
record(s"foldOver $getClass")
65646566
record(s"foldOver total")
65656567
tp match {
6566-
case tp: TypeRef =>
6568+
case tp: NamedType =>
65676569
if stopBecauseStaticOrLocal(tp) then x
65686570
else
65696571
val tp1 = tp.prefix.lookupRefined(tp.name)
@@ -6592,8 +6594,8 @@ object Types extends TypeUtils {
65926594
variance = saved
65936595
this(y, restpe)
65946596

6595-
case tp: TermRef =>
6596-
if stopBecauseStaticOrLocal(tp) then x else applyToPrefix(x, tp)
6597+
//case tp: TermRef =>
6598+
// if stopBecauseStaticOrLocal(tp) then x else applyToPrefix(x, tp)
65976599

65986600
case tp: TypeVar =>
65996601
this(x, tp.underlying)

0 commit comments

Comments
 (0)