Skip to content

Commit 5058dc8

Browse files
committed
Refine atoms computation some more.
If we have `x: 0 | 1` then `x.type` should have atoms {`0`, `1`} only if widening is allowed. On the other hand, if `x: 0` then `x` has atoms `{0}`irrespective of widening.
1 parent 0fdcc3f commit 5058dc8

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,8 +1188,9 @@ object Types {
11881188
case _ => tp
11891189
}
11901190
val underlyingAtoms = tp.underlying.atoms(widenOK)
1191-
if (underlyingAtoms.isEmpty && tp.isStable) Set.empty + normalize(tp)
1192-
else underlyingAtoms
1191+
if underlyingAtoms.isEmpty && tp.isStable then Set.empty + normalize(tp)
1192+
else if underlyingAtoms.size == 1 || widenOK then underlyingAtoms
1193+
else Set.empty
11931194
case tp: ExprType => tp.resType.atoms(widenOK)
11941195
case tp: OrType => tp.atoms(widenOK) // `atoms` overridden in OrType
11951196
case tp: AndType => tp.tp1.atoms(widenOK) & tp.tp2.atoms(widenOK)

tests/pos/i8128.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
object Test {
2-
def id: (x: 1 | 0) => x.type = x => x
3-
id(0): 0 // fails
2+
def id: (x: 1 | 0) => x.type = ???
3+
id(0): 0 // ok
44

55
def id2: Function1[1 | 0, 1 | 0] {
66
def apply(x: 1 | 0): x.type
77
} = ???
8-
id2(0): 0 // fails
8+
id2(0): 0 // ok
99

1010
def id3: Function1[1 | 0, Int] {
1111
def apply(x: 1 | 0): x.type

0 commit comments

Comments
 (0)