@@ -427,20 +427,6 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
427
427
}
428
428
}
429
429
430
- /* Erase a type binding according to erasure semantics in pattern matching */
431
- def erase (tp : Type ): Type = {
432
- tp match {
433
- case tp @ AppliedType (tycon, args) => erase(tp.superType)
434
- if (tycon.isRef(defn.ArrayClass )) tp.derivedAppliedType(tycon, args.map(erase))
435
- else tp.derivedAppliedType(tycon, args.map(t => WildcardType (TypeBounds .empty)))
436
- case OrType (tp1, tp2) =>
437
- OrType (erase(tp1), erase(tp2))
438
- case AndType (tp1, tp2) =>
439
- AndType (erase(tp1), erase(tp2))
440
- case _ => tp
441
- }
442
- }
443
-
444
430
/** Is `tp1` a subtype of `tp2`? */
445
431
def isSubType (tp1 : Type , tp2 : Type ): Boolean = {
446
432
val res = tp1 <:< tp2
@@ -544,14 +530,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
544
530
545
531
val childTp = if (child.isTerm) child.termRef else child.typeRef
546
532
547
- var resTp = instantiate(childTp, parent)(ctx.fresh.setNewTyperState)
548
-
549
- // try expose references to type parameters in the parent type
550
- //
551
- // tests/patmat/t9657.scala
552
- // tests/patmat/gadt.scala LOC#50
553
- //
554
- // if (!resTp.exists) resTp = instantiate(childTp, expose(parent))(ctx.fresh.setNewTyperState)
533
+ var resTp = instantiate(childTp, expose(parent))(ctx.fresh.setNewTyperState)
555
534
556
535
if (! resTp.exists) {
557
536
debug.println(s " [refine] unqualified child ousted: ${childTp.show} !< ${parent.show}" )
@@ -586,9 +565,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
586
565
val tvars = tp1.typeParams.map { tparam => newTypeVar(tparam.paramInfo.bounds) }
587
566
val protoTp1 = thisTypeMap(tp1.appliedTo(tvars))
588
567
589
- // try expose references to type parameters in the parent type
590
- // tests/patmat/t9657.scala
591
- // tests/patmat/gadt.scala LOC#50
568
+ // replace type parameter references with fresh type vars or bounds
592
569
val typeParamMap = new TypeMap {
593
570
def apply (t : Type ): Type = t match {
594
571
case tp : TypeRef if tp.underlying.isInstanceOf [TypeBounds ] =>
@@ -599,7 +576,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
599
576
newTypeVar(bound)
600
577
case tp : RefinedType if tp.refinedInfo.isInstanceOf [TypeBounds ] =>
601
578
// Ideally, we would expect type inference can do the job
602
- // tp.derivedRefinedType(tp.parent, tp.refinedName, TypeAlias(newTypeVar(tp.refinedInfo.bounds)))
579
+ // tests/patmat/t9657.scala
603
580
expose(tp)
604
581
case _ =>
605
582
mapOver(t)
@@ -753,51 +730,50 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
753
730
}
754
731
755
732
756
- /** Expose type to eliminate reference to type parameters
733
+ /** Eliminate reference to type parameters in refinements
757
734
*
758
735
* A <: X :> Y B <: U :> V M { type T <: A :> B } ~~> M { type T <: X :> V }
759
736
*/
760
- def expose (tp : Type , up : Boolean = true ): Type = {
761
- tp match {
762
- case tp : AppliedType =>
763
- tp.derivedAppliedType(expose(tp.tycon, up), tp.args.map(expose(_, up)))
737
+ def expose (tp : Type , refineCtx : Boolean = false , up : Boolean = true ): Type = tp match {
738
+ case tp : AppliedType =>
739
+ tp.derivedAppliedType(expose(tp.tycon, refineCtx, up), tp.args.map(expose(_, refineCtx, up)))
764
740
765
- case tp : TypeAlias =>
766
- val hi = expose(tp.alias, true )
767
- val lo = expose(tp.alias, false )
741
+ case tp : TypeAlias =>
742
+ val hi = expose(tp.alias, refineCtx, up )
743
+ val lo = expose(tp.alias, refineCtx, up )
768
744
769
- if (hi =:= lo)
770
- tp.derivedTypeAlias(hi)
771
- else
772
- tp.derivedTypeBounds(lo, hi)
773
-
774
- case tp @ TypeBounds (lo, hi) =>
775
- tp.derivedTypeBounds(expose(lo, false ), expose(hi, true ))
776
-
777
- case tp : RefinedType =>
778
- tp.derivedRefinedType(
779
- expose(tp.parent),
780
- tp.refinedName,
781
- expose(tp.refinedInfo)
782
- )
783
- case tp : TypeProxy =>
784
- tp.underlying match {
785
- case TypeBounds (lo, hi) =>
786
- expose(if (up) hi else lo, up)
787
- case _ =>
788
- tp
789
- }
745
+ if (hi =:= lo)
746
+ tp.derivedTypeAlias(hi)
747
+ else
748
+ tp.derivedTypeBounds(lo, hi)
790
749
791
- case OrType (tp1, tp2 ) =>
792
- OrType (expose(tp1, up ), expose(tp2, up ))
750
+ case tp @ TypeBounds (lo, hi ) =>
751
+ tp.derivedTypeBounds (expose(lo, refineCtx, false ), expose(hi, refineCtx, true ))
793
752
794
- case AndType (tp1, tp2) =>
795
- AndType (expose(tp1, up), expose(tp2, up))
753
+ case tp : RefinedType =>
754
+ tp.derivedRefinedType(
755
+ expose(tp.parent),
756
+ tp.refinedName,
757
+ expose(tp.refinedInfo, true , up)
758
+ )
759
+ case tp : TypeProxy if refineCtx =>
760
+ tp.underlying match {
761
+ case TypeBounds (lo, hi) =>
762
+ expose(if (up) hi else lo, refineCtx, up)
763
+ case _ =>
764
+ tp
765
+ }
796
766
797
- case _ => tp
798
- }
767
+ case OrType (tp1, tp2) =>
768
+ OrType (expose(tp1, refineCtx, up), expose(tp2, refineCtx, up))
769
+
770
+ case AndType (tp1, tp2) =>
771
+ AndType (expose(tp1, refineCtx, up), expose(tp2, refineCtx, up))
772
+
773
+ case _ => tp
799
774
}
800
775
776
+
801
777
def checkExhaustivity (_match : Match ): Unit = {
802
778
val Match (sel, cases) = _match
803
779
val selTyp = sel.tpe.widen.dealias
0 commit comments