@@ -1282,13 +1282,10 @@ object Types {
1282
1282
case tp =>
1283
1283
tp.widenUnionWithoutNull
1284
1284
1285
+ /** Overridden in OrType */
1285
1286
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)
1292
1289
case tp : RefinedType =>
1293
1290
tp.derivedRefinedType(tp.parent.widenUnion, tp.refinedName, tp.refinedInfo)
1294
1291
case tp : RecType =>
@@ -3198,6 +3195,20 @@ object Types {
3198
3195
myJoin
3199
3196
}
3200
3197
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
+
3201
3212
private var atomsRunId : RunId = NoRunId
3202
3213
private var myAtoms : Atoms = _
3203
3214
private var myWidened : Type = _
0 commit comments