@@ -187,25 +187,19 @@ object SpaceEngine {
187
187
else if (isSubType(tp2, tp1)) b
188
188
else if (canDecompose(tp1)) tryDecompose1(tp1)
189
189
else if (canDecompose(tp2)) tryDecompose2(tp2)
190
- else intersectUnrelatedAtomicTypes(tp1, tp2)
190
+ else intersectUnrelatedAtomicTypes(tp1, tp2)(a)
191
191
case (Typ (tp1, _), Prod (tp2, fun, ss)) =>
192
192
if (isSubType(tp2, tp1)) b
193
193
else if (canDecompose(tp1)) tryDecompose1(tp1)
194
194
else if (isSubType(tp1, tp2)) a // problematic corner case: inheriting a case class
195
- else intersectUnrelatedAtomicTypes(tp1, tp2) match
196
- case Typ (tp, _) => Prod (tp, fun, ss)
197
- case sp => sp
195
+ else intersectUnrelatedAtomicTypes(tp1, tp2)(b)
198
196
case (Prod (tp1, fun, ss), Typ (tp2, _)) =>
199
197
if (isSubType(tp1, tp2)) a
200
198
else if (canDecompose(tp2)) tryDecompose2(tp2)
201
199
else if (isSubType(tp2, tp1)) a // problematic corner case: inheriting a case class
202
- else intersectUnrelatedAtomicTypes(tp1, tp2) match
203
- case Typ (tp, _) => Prod (tp, fun, ss)
204
- case sp => sp
200
+ else intersectUnrelatedAtomicTypes(tp1, tp2)(a)
205
201
case (Prod (tp1, fun1, ss1), Prod (tp2, fun2, ss2)) =>
206
- if (! isSameUnapply(fun1, fun2)) intersectUnrelatedAtomicTypes(tp1, tp2) match
207
- case Typ (tp, _) => Prod (tp, fun1, ss1)
208
- case sp => sp
202
+ if (! isSameUnapply(fun1, fun2)) intersectUnrelatedAtomicTypes(tp1, tp2)(a)
209
203
else if (ss1.zip(ss2).exists(p => simplify(intersect(p._1, p._2)) == Empty )) Empty
210
204
else Prod (tp1, fun1, ss1.zip(ss2).map((intersect _).tupled))
211
205
}
@@ -323,13 +317,15 @@ object SpaceEngine {
323
317
* The types should be atomic (non-decomposable) and unrelated (neither
324
318
* should be a subtype of the other).
325
319
*/
326
- def intersectUnrelatedAtomicTypes (tp1 : Type , tp2 : Type )(using Context ): Space = trace(i " atomic intersection: ${AndType (tp1, tp2)}" , debug) {
320
+ def intersectUnrelatedAtomicTypes (tp1 : Type , tp2 : Type )(sp : Space )( using Context ): Space = trace(i " atomic intersection: ${AndType (tp1, tp2)}" , debug) {
327
321
// Precondition: !isSubType(tp1, tp2) && !isSubType(tp2, tp1).
328
322
if ! ctx.mode.is(Mode .SafeNulls ) && (tp1.isNullType || tp2.isNullType) then
329
323
// Since projections of types don't include null, intersection with null is empty.
330
324
Empty
331
325
else
332
- val intersection = Typ (AndType (tp1, tp2), decomposed = false )
326
+ val intersection = sp match
327
+ case sp : Prod => sp.copy(AndType (tp1, tp2))
328
+ case _ => Typ (AndType (tp1, tp2), decomposed = false )
333
329
// unrelated numeric value classes can equal each other, so let's not consider type space intersection empty
334
330
if tp1.classSymbol.isNumericValueClass && tp2.classSymbol.isNumericValueClass then intersection
335
331
else if isPrimToBox(tp1, tp2) || isPrimToBox(tp2, tp1) then intersection
0 commit comments