Skip to content

Commit 1948a8d

Browse files
committed
Preserve hard unions in widenSingletons
1 parent af655c9 commit 1948a8d

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3630,7 +3630,7 @@ object Types extends TypeUtils {
36303630
myAtoms
36313631

36323632
override def widenSingletons(skipSoftUnions: Boolean)(using Context): Type =
3633-
if isSoft && skipSoftUnions then this
3633+
if !isSoft || skipSoftUnions then this
36343634
else
36353635
if widenedRunId != ctx.runId then
36363636
myWidened = computeWidenSingletons()

tests/pos/22219.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type MonthNumber = 1 | 2
2+
3+
def main =
4+
val x = 1: MonthNumber
5+
val y: MonthNumber = x

tests/pos/22219b.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
type MonthNumber =
2+
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12
3+
4+
def main =
5+
List[(String, MonthNumber)](
6+
"January" -> 1,
7+
"February" -> 2,
8+
"March" -> 3,
9+
"April" -> 4,
10+
"May" -> 5,
11+
"June"-> 6,
12+
"July" -> 7,
13+
"August" -> 8,
14+
"September" -> 9,
15+
"October" -> 10,
16+
"November" -> 11,
17+
"December" -> 12
18+
).foreach { (name, number) =>
19+
summon[number.type <:< MonthNumber]
20+
}

0 commit comments

Comments
 (0)