@@ -1282,13 +1282,10 @@ object Types {
12821282 case tp =>
12831283 tp.widenUnionWithoutNull
12841284
1285+ /** Overridden in OrType */
12851286 def widenUnionWithoutNull (using Context ): Type = widen match
1286- case tp @ OrType (lhs, rhs) if tp.isSoft =>
1287- TypeComparer .lub(lhs.widenUnionWithoutNull, rhs.widenUnionWithoutNull, canConstrain = true ) match
1288- case union : OrType => union.join
1289- case res => res
1290- case tp : AndOrType =>
1291- tp.derivedAndOrType(tp.tp1.widenUnionWithoutNull, tp.tp2.widenUnionWithoutNull)
1287+ case tp : AndType =>
1288+ tp.derivedAndType(tp.tp1.widenUnionWithoutNull, tp.tp2.widenUnionWithoutNull)
12921289 case tp : RefinedType =>
12931290 tp.derivedRefinedType(tp.parent.widenUnion, tp.refinedName, tp.refinedInfo)
12941291 case tp : RecType =>
@@ -3198,6 +3195,20 @@ object Types {
31983195 myJoin
31993196 }
32003197
3198+ private var myUnion : Type = _
3199+ private var myUnionPeriod : Period = Nowhere
3200+
3201+ override def widenUnionWithoutNull (using Context ): Type =
3202+ if myUnionPeriod != ctx.period then
3203+ myUnion =
3204+ if isSoft then
3205+ TypeComparer .lub(tp1.widenUnionWithoutNull, tp2.widenUnionWithoutNull, canConstrain = true ) match
3206+ case union : OrType => union.join
3207+ case res => res
3208+ else derivedOrType(tp1.widenUnionWithoutNull, tp2.widenUnionWithoutNull)
3209+ if ! isProvisional then myUnionPeriod = ctx.period
3210+ myUnion
3211+
32013212 private var atomsRunId : RunId = NoRunId
32023213 private var myAtoms : Atoms = _
32033214 private var myWidened : Type = _
0 commit comments