Skip to content

Commit 833679a

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 d2cc3ae commit 833679a

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
@@ -1641,6 +1641,8 @@ object Types extends TypeUtils {
16411641
pre.refinedInfo match {
16421642
case tp: AliasingBounds =>
16431643
if (pre.refinedName ne name) loop(pre.parent) else tp.alias
1644+
case tp: SingletonType =>
1645+
if pre.refinedName ne name then loop(pre.parent) else tp
16441646
case _ =>
16451647
loop(pre.parent)
16461648
}
@@ -2668,7 +2670,7 @@ object Types extends TypeUtils {
26682670
* refinement type `T { X = U; ... }`
26692671
*/
26702672
def reduceProjection(using Context): Type =
2671-
if (isType) {
2673+
if (isType || true) {
26722674
val reduced = prefix.lookupRefined(name)
26732675
if (reduced.exists) reduced else this
26742676
}
@@ -2757,14 +2759,14 @@ object Types extends TypeUtils {
27572759
* (S | T)#A --> S#A | T#A
27582760
*/
27592761
def derivedSelect(prefix: Type)(using Context): Type =
2760-
if (prefix eq this.prefix) this
2761-
else if (prefix.isExactlyNothing) prefix
2762+
if prefix eq this.prefix then this
2763+
else if prefix.isExactlyNothing then prefix
27622764
else {
2765+
val res =
2766+
if (isType && currentValidSymbol.isAllOf(ClassTypeParam)) argForParam(prefix)
2767+
else prefix.lookupRefined(name)
2768+
if (res.exists) return res
27632769
if (isType) {
2764-
val res =
2765-
if (currentValidSymbol.isAllOf(ClassTypeParam)) argForParam(prefix)
2766-
else prefix.lookupRefined(name)
2767-
if (res.exists) return res
27682770
if (Config.splitProjections)
27692771
prefix match {
27702772
case prefix: AndType =>
@@ -6526,7 +6528,7 @@ object Types extends TypeUtils {
65266528
record(s"foldOver $getClass")
65276529
record(s"foldOver total")
65286530
tp match {
6529-
case tp: TypeRef =>
6531+
case tp: NamedType =>
65306532
if stopBecauseStaticOrLocal(tp) then x
65316533
else
65326534
val tp1 = tp.prefix.lookupRefined(tp.name)
@@ -6555,8 +6557,8 @@ object Types extends TypeUtils {
65556557
variance = saved
65566558
this(y, restpe)
65576559

6558-
case tp: TermRef =>
6559-
if stopBecauseStaticOrLocal(tp) then x else applyToPrefix(x, tp)
6560+
//case tp: TermRef =>
6561+
// if stopBecauseStaticOrLocal(tp) then x else applyToPrefix(x, tp)
65606562

65616563
case tp: TypeVar =>
65626564
this(x, tp.underlying)

0 commit comments

Comments
 (0)