@@ -79,8 +79,13 @@ trait SpaceLogic {
79
79
/** Is `tp1` a subtype of `tp2`? */
80
80
def isSubType (tp1 : Type , tp2 : Type ): Boolean
81
81
82
- /** Is `tp1` the same type as `tp2`? */
83
- def isEqualType (tp1 : Type , tp2 : Type ): Boolean
82
+ /** Whether we may assume the two Unapply the same?
83
+ * That is, given the same parameter, returns the same result.
84
+ *
85
+ * This is more general than purity, as the same `unapply` method may
86
+ * take different prefix, thus behaves differently.
87
+ */
88
+ def isSameUnapply (tp1 : TermRef , tp2 : TermRef ): Boolean
84
89
85
90
/** Return a space containing the values of both types.
86
91
*
@@ -179,7 +184,7 @@ trait SpaceLogic {
179
184
// approximation: a type can never be fully matched by a partial extractor
180
185
full && isSubType(tp1, tp2) && isSubspace(Prod (tp2, fun, signature(fun, tp2, ss.length).map(Typ (_, false )), full), b)
181
186
case (Prod (_, fun1, ss1, _), Prod (_, fun2, ss2, _)) =>
182
- isEqualType (fun1, fun2) && ss1.zip(ss2).forall((isSubspace _).tupled)
187
+ isSameUnapply (fun1, fun2) && ss1.zip(ss2).forall((isSubspace _).tupled)
183
188
}
184
189
}
185
190
@@ -217,7 +222,7 @@ trait SpaceLogic {
217
222
else if (canDecompose(tp2)) tryDecompose2(tp2)
218
223
else Empty
219
224
case (Prod (tp1, fun1, ss1, full), Prod (tp2, fun2, ss2, _)) =>
220
- if (! isEqualType (fun1, fun2)) Empty
225
+ if (! isSameUnapply (fun1, fun2)) Empty
221
226
else if (ss1.zip(ss2).exists(p => simplify(intersect(p._1, p._2)) == Empty )) Empty
222
227
else Prod (tp1, fun1, ss1.zip(ss2).map((intersect _).tupled), full)
223
228
}
@@ -257,7 +262,7 @@ trait SpaceLogic {
257
262
case (Typ (tp1, _), Prod (tp2, _, _, false )) =>
258
263
a // approximation
259
264
case (Prod (tp1, fun1, ss1, full), Prod (tp2, fun2, ss2, _)) =>
260
- if (! isEqualType (fun1, fun2)) a
265
+ if (! isSameUnapply (fun1, fun2)) a
261
266
else if (ss1.zip(ss2).exists(p => simplify(intersect(p._1, p._2)) == Empty )) a
262
267
else if (ss1.zip(ss2).forall((isSubspace _).tupled)) Empty
263
268
else
@@ -499,7 +504,8 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
499
504
res
500
505
}
501
506
502
- def isEqualType (tp1 : Type , tp2 : Type ): Boolean = tp1 =:= tp2
507
+ def isSameUnapply (tp1 : TermRef , tp2 : TermRef ): Boolean =
508
+ tp1.prefix.isStable && tp2.prefix.isStable && tp1 =:= tp2
503
509
504
510
/** Parameter types of the case class type `tp`. Adapted from `unapplyPlan` in patternMatcher */
505
511
def signature (unapp : TermRef , scrutineeTp : Type , argLen : Int ): List [Type ] = {
0 commit comments