@@ -267,8 +267,8 @@ trait SpaceLogic {
267
267
else
268
268
// `(_, _, _) - (Some, None, _)` becomes `(None, _, _) | (_, Some, _) | (_, _, Empty)`
269
269
Or (ss1.zip(ss2).map((minus _).tupled).zip(0 to ss2.length - 1 ).map {
270
- case (ri, i) => Prod (tp1, fun1, sym1, ss1.updated(i, ri), full)
271
- })
270
+ case (ri, i) => Prod (tp1, fun1, sym1, ss1.updated(i, ri), full)
271
+ })
272
272
273
273
}
274
274
@@ -375,7 +375,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
375
375
}
376
376
377
377
/* Whether the extractor is irrefutable */
378
- def irrefutable (unapp : tpd. Tree ): Boolean = {
378
+ def irrefutable (unapp : Tree ): Boolean = {
379
379
// TODO: optionless patmat
380
380
unapp.tpe.widen.finalResultType.isRef(scalaSomeClass) ||
381
381
(unapp.symbol.is(Synthetic ) && unapp.symbol.owner.linkedClass.is(Case )) ||
@@ -557,11 +557,11 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
557
557
def refine (parent : Type , child : Symbol ): Type = {
558
558
if (child.isTerm && child.is(Case , butNot = Module )) return child.termRef // enum vals always match
559
559
560
- val childTp = if (child.isTerm) child.termRef else child.typeRef
560
+ val childTp = if (child.isTerm) child.termRef else child.typeRef
561
561
562
562
val resTp = instantiate(childTp, parent)(ctx.fresh.setNewTyperState())
563
563
564
- if (! resTp.exists) {
564
+ if (! resTp.exists || ! inhabited(resTp)) {
565
565
debug.println(s " [refine] unqualified child ousted: ${childTp.show} !< ${parent.show}" )
566
566
NoType
567
567
}
@@ -571,6 +571,25 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
571
571
}
572
572
}
573
573
574
+ /** Can this type be inhabited by a value?
575
+ *
576
+ * Intersection between singleton types and other types is always empty
577
+ * the singleton type is not a subtype of the other type.
578
+ * See patmat/i3573.scala for an example.
579
+ */
580
+ def inhabited (tpe : Type )(implicit ctx : Context ): Boolean = {
581
+ val emptySingletonIntersection = new ExistsAccumulator ({
582
+ case AndType (s : SingletonType , t) =>
583
+ ! (s <:< t)
584
+ case AndType (t, s : SingletonType ) =>
585
+ ! (s <:< t)
586
+ case x =>
587
+ false
588
+ })
589
+
590
+ ! emptySingletonIntersection(false , tpe)
591
+ }
592
+
574
593
/** Instantiate type `tp1` to be a subtype of `tp2`
575
594
*
576
595
* Return the instantiated type if type parameters and this type
0 commit comments