@@ -1193,7 +1193,7 @@ object Types {
11931193 else tp.derivedOrType(tp1Widen, defn.NullType )
11941194 case tp =>
11951195 tp.widenUnionWithoutNull
1196- }.reporting( i " widenUnion( $this ) = $result " )
1196+ }
11971197
11981198 def widenUnionWithoutNull (using Context ): Type =
11991199
@@ -1214,19 +1214,28 @@ object Types {
12141214
12151215 def recombine (tp1 : Type , tp2 : Type ) = harden(TypeComparer .lub(tp1, tp2))
12161216
1217+ inline val asymmetric = false
1218+
12171219 widen match
12181220 case tp @ OrType (lhs, rhs) =>
1219- if tp.isSoft then
1220- val (lhsCore, lhsExtras) = splitAlts(lhs.widenUnionWithoutNull, Nil )
1221- val (rhsCore, rhsExtras) = splitAlts(rhs.widenUnionWithoutNull, Nil )
1222- val core = TypeComparer .lub(lhsCore, rhsCore, canConstrain = true ) match
1221+ if asymmetric then
1222+ if tp.isSoft then
1223+ val (lhsCore, lhsExtras) = splitAlts(lhs.widenUnionWithoutNull, Nil )
1224+ val (rhsCore, rhsExtras) = splitAlts(rhs.widenUnionWithoutNull, Nil )
1225+ val core = TypeComparer .lub(lhsCore, rhsCore, canConstrain = true ) match
1226+ case union : OrType => union.join
1227+ case res => res
1228+ rhsExtras.foldLeft(lhsExtras.foldLeft(core)(recombine))(recombine)
1229+ else
1230+ val lhs1 = lhs.widenUnionWithoutNull
1231+ val rhs1 = rhs.widenUnionWithoutNull
1232+ if (lhs1 eq lhs) && (rhs1 eq rhs) then tp else recombine(lhs1, rhs1)
1233+ else if tp.isSoft then
1234+ TypeComparer .lub(lhs.widenUnionWithoutNull, rhs.widenUnionWithoutNull, canConstrain = true ) match
12231235 case union : OrType => union.join
12241236 case res => res
1225- rhsExtras.foldLeft(lhsExtras.foldLeft(core)(recombine))(recombine)
12261237 else
1227- val lhs1 = lhs.widenUnionWithoutNull
1228- val rhs1 = rhs.widenUnionWithoutNull
1229- if (lhs1 eq lhs) && (rhs1 eq rhs) then tp else recombine(lhs1, rhs1)
1238+ tp.derivedOrType(lhs.widenUnionWithoutNull, rhs.widenUnionWithoutNull)
12301239 case tp @ AndType (tp1, tp2) =>
12311240 tp derived_& (tp1.widenUnionWithoutNull, tp2.widenUnionWithoutNull)
12321241 case tp : RefinedType =>
0 commit comments