Skip to content

Commit e5c8238

Browse files
authored
Merge pull request scala#14399 from dotty-staging/mb/singletons-in-hard-unions
2 parents e45dd62 + 594e168 commit e5c8238

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3263,10 +3263,10 @@ object Types {
32633263
if myUnionPeriod != ctx.period then
32643264
myUnion =
32653265
if isSoft then
3266-
TypeComparer.lub(tp1.widenUnionWithoutNull, tp2.widenUnionWithoutNull, canConstrain = true) match
3266+
TypeComparer.lub(tp1.widenUnionWithoutNull, tp2.widenUnionWithoutNull, canConstrain = true, isSoft = isSoft) match
32673267
case union: OrType => union.join
32683268
case res => res
3269-
else derivedOrType(tp1.widenUnionWithoutNull, tp2.widenUnionWithoutNull)
3269+
else derivedOrType(tp1.widenUnionWithoutNull, tp2.widenUnionWithoutNull, soft = isSoft)
32703270
if !isProvisional then myUnionPeriod = ctx.period
32713271
myUnion
32723272

@@ -3282,7 +3282,7 @@ object Types {
32823282
else tp1.atoms | tp2.atoms
32833283
val tp1w = tp1.widenSingletons
32843284
val tp2w = tp2.widenSingletons
3285-
myWidened = if ((tp1 eq tp1w) && (tp2 eq tp2w)) this else tp1w | tp2w
3285+
myWidened = if ((tp1 eq tp1w) && (tp2 eq tp2w)) this else TypeComparer.lub(tp1w, tp2w, isSoft = isSoft)
32863286
atomsRunId = ctx.runId
32873287

32883288
override def atoms(using Context): Atoms =

tests/pos/widen-union.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@ object Test1:
55
val z: Int | String = y
66

77
object Test2:
8+
val x: 3 | "a" = 3
9+
val y = x
10+
val z: Int | String = y
11+
12+
object Test3:
813
type Sig = Int | String
914
def consistent(x: Sig, y: Sig): Boolean = ???// x == y
1015

1116
def consistentLists(xs: List[Sig], ys: List[Sig]): Boolean =
1217
xs.corresponds(ys)(consistent) // OK
1318
|| xs.corresponds(ys)(consistent(_, _)) // error, found: Any, required: Int | String
1419

15-
object Test3:
20+
object Test4:
1621

1722
def g[X](x: X | String): Int = ???
1823
def y: Boolean | String = ???

0 commit comments

Comments
 (0)