@@ -375,7 +375,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
375375 }
376376
377377 /* Whether the extractor is irrefutable */
378- def irrefutable (unapp : tpd. Tree ): Boolean = {
378+ def irrefutable (unapp : Tree ): Boolean = {
379379 // TODO: optionless patmat
380380 unapp.tpe.widen.finalResultType.isRef(scalaSomeClass) ||
381381 (unapp.symbol.is(Synthetic ) && unapp.symbol.owner.linkedClass.is(Case )) ||
@@ -557,11 +557,11 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
557557 def refine (parent : Type , child : Symbol ): Type = {
558558 if (child.isTerm && child.is(Case , butNot = Module )) return child.termRef // enum vals always match
559559
560- val childTp = if (child.isTerm) child.termRef else child.typeRef
560+ val childTp = if (child.isTerm) child.termRef else child.typeRef
561561
562562 val resTp = instantiate(childTp, parent)(ctx.fresh.setNewTyperState())
563563
564- if (! resTp.exists) {
564+ if (! resTp.exists) {
565565 debug.println(s " [refine] unqualified child ousted: ${childTp.show} !< ${parent.show}" )
566566 NoType
567567 }
@@ -625,7 +625,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
625625 val tvars = tp1.typeParams.map { tparam => newTypeVar(tparam.paramInfo.bounds) }
626626 val protoTp1 = thisTypeMap(tp1.appliedTo(tvars))
627627
628- if (protoTp1 <:< tp2) {
628+ val result = if (protoTp1 <:< tp2) {
629629 if (isFullyDefined(protoTp1, force)) protoTp1
630630 else instUndetMap(protoTp1)
631631 }
@@ -640,6 +640,24 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
640640 NoType
641641 }
642642 }
643+
644+ // The intersection between a singleton type s and another type t is
645+ // always empty when s is not a subtype of t. See patmat/i3573.scala
646+ val hasEmptyIntersections = new ExistsAccumulator ({
647+ case AndType (s : SingletonType , t) =>
648+ ! (s <:< t)
649+ case AndType (t, s : SingletonType ) =>
650+ ! (s <:< t)
651+ case x =>
652+ false
653+ })
654+
655+ if (hasEmptyIntersections(false , result)) {
656+ debug.println(s " hasEmptyIntersections( $protoTp1) = true " )
657+ NoType
658+ } else {
659+ result
660+ }
643661 }
644662
645663 /** Abstract sealed types, or-types, Boolean and Java enums can be decomposed */
0 commit comments