Skip to content

Commit

Permalink
Merge pull request #14399 from dotty-staging/mb/singletons-in-hard-un…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
dwijnand authored Feb 2, 2022
2 parents e45dd62 + 594e168 commit e5c8238
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3263,10 +3263,10 @@ object Types {
if myUnionPeriod != ctx.period then
myUnion =
if isSoft then
TypeComparer.lub(tp1.widenUnionWithoutNull, tp2.widenUnionWithoutNull, canConstrain = true) match
TypeComparer.lub(tp1.widenUnionWithoutNull, tp2.widenUnionWithoutNull, canConstrain = true, isSoft = isSoft) match
case union: OrType => union.join
case res => res
else derivedOrType(tp1.widenUnionWithoutNull, tp2.widenUnionWithoutNull)
else derivedOrType(tp1.widenUnionWithoutNull, tp2.widenUnionWithoutNull, soft = isSoft)
if !isProvisional then myUnionPeriod = ctx.period
myUnion

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

override def atoms(using Context): Atoms =
Expand Down
7 changes: 6 additions & 1 deletion tests/pos/widen-union.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@ object Test1:
val z: Int | String = y

object Test2:
val x: 3 | "a" = 3
val y = x
val z: Int | String = y

object Test3:
type Sig = Int | String
def consistent(x: Sig, y: Sig): Boolean = ???// x == y

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

object Test3:
object Test4:

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

0 comments on commit e5c8238

Please sign in to comment.