@@ -74,14 +74,12 @@ trait SpaceLogic {
74
74
/** Is `tp1` the same type as `tp2`? */
75
75
def isEqualType (tp1 : Type , tp2 : Type ): Boolean
76
76
77
- /** Can `tp` be arbitrarily subtyped by any other open type? */
78
- def isOpen (tp : Type ): Boolean
79
-
80
- /** Construct a space which contains values from both `tp1` and `tp2`.
77
+ /** Return a space containing the values of both types.
81
78
*
82
- * Both types are expected to be open in the [[isOpen ]] sense.
79
+ * The types should be atomic (non-decomposable) and unrelated (neither
80
+ * should be a subtype of the other).
83
81
*/
84
- def commonOpenTypeSpace (tp1 : Type , tp2 : Type ): Space
82
+ def intersectUnrelatedAtomicTypes (tp1 : Type , tp2 : Type ): Space
85
83
86
84
/** Is the type `tp` decomposable? i.e. all values of the type can be covered
87
85
* by its decomposed types.
@@ -180,8 +178,7 @@ trait SpaceLogic {
180
178
else if (isSubType(tp2, tp1)) b
181
179
else if (canDecompose(tp1)) tryDecompose1(tp1)
182
180
else if (canDecompose(tp2)) tryDecompose2(tp2)
183
- else if (isOpen(tp1) && isOpen(tp2)) commonOpenTypeSpace(tp1, tp2)
184
- else Empty
181
+ else intersectUnrelatedAtomicTypes(tp1, tp2)
185
182
case (Typ (tp1, _), Kon (tp2, ss)) =>
186
183
if (isSubType(tp2, tp1)) b
187
184
else if (isSubType(tp1, tp2)) a // problematic corner case: inheriting a case class
@@ -253,10 +250,15 @@ trait SpaceLogic {
253
250
class SpaceEngine (implicit ctx : Context ) extends SpaceLogic {
254
251
import tpd ._
255
252
256
- override def isOpen (tp : Type ) =
257
- ! tp.classSymbol.is(Sealed | Final ) && ! tp.termSymbol.is(Module )
253
+ override def intersectUnrelatedAtomicTypes (tp1 : Type , tp2 : Type ) = {
254
+ def isOpen (tp : Type ) =
255
+ ! tp.classSymbol.is(Sealed | Final ) && ! tp.termSymbol.is(Module )
258
256
259
- override def commonOpenTypeSpace (tp1 : Type , tp2 : Type ) = Typ (AndType (tp1, tp2), true )
257
+ if ((tp1.classSymbol.is(Trait ) || tp2.classSymbol.is(Trait ))
258
+ && isOpen(tp1) && isOpen(tp2))
259
+ Typ (AndType (tp1, tp2), true )
260
+ else Empty
261
+ }
260
262
261
263
/** Return the space that represents the pattern `pat`
262
264
*
0 commit comments