@@ -606,20 +606,19 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
606
606
}
607
607
}
608
608
609
- val tvars = tp1.typeParams.map { tparam => newTypeVar(tparam.paramInfo.bounds) }
610
- val protoTp1 = thisTypeMap(tp1.appliedTo(tvars))
611
-
612
- // replace type parameter references with fresh type vars or bounds
609
+ // replace type parameter references with bounds
613
610
val typeParamMap = new TypeMap {
614
611
def apply (t : Type ): Type = t match {
615
612
616
613
case tp : TypeRef if tp.symbol.is(TypeParam ) && tp.underlying.isInstanceOf [TypeBounds ] =>
617
614
// See tests/patmat/gadt.scala tests/patmat/exhausting.scala
618
- val bound =
619
- if (variance == 0 ) tp.underlying.bounds // non-variant case is not well-founded
620
- else if (variance == 1 ) TypeBounds .upper(tp)
621
- else TypeBounds .lower(tp)
622
- newTypeVar(bound)
615
+ val exposed =
616
+ if (variance == 0 ) newTypeVar(tp.underlying.bounds)
617
+ else if (variance == 1 ) expose(tp, true )
618
+ else expose(tp, false )
619
+
620
+ debug.println(s " $tp exposed to =====> " + exposed)
621
+ exposed
623
622
case tp : RefinedType if tp.refinedInfo.isInstanceOf [TypeBounds ] =>
624
623
// Ideally, we would expect type inference to do the job
625
624
// Check tests/patmat/t9657.scala
@@ -629,6 +628,9 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
629
628
}
630
629
}
631
630
631
+ val tvars = tp1.typeParams.map { tparam => newTypeVar(tparam.paramInfo.bounds) }
632
+ val protoTp1 = thisTypeMap(tp1.appliedTo(tvars))
633
+
632
634
if (protoTp1 <:< tp2 && isFullyDefined(protoTp1, ForceDegree .noBottom)) protoTp1
633
635
else {
634
636
val protoTp2 = typeParamMap(tp2)
@@ -778,41 +780,41 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
778
780
*
779
781
* A <: X :> Y B <: U :> V M { type T <: A :> B } ~~> M { type T <: X :> V }
780
782
*/
781
- def expose (tp : Type , refineCtx : Boolean = false , up : Boolean = true ): Type = tp match {
783
+ def expose (tp : Type , up : Boolean = true ): Type = tp match {
782
784
case tp : AppliedType =>
783
- tp.derivedAppliedType(expose(tp.tycon, refineCtx, up), tp.args.map(expose(_, refineCtx , up)))
785
+ tp.derivedAppliedType(expose(tp.tycon, up), tp.args.map(expose(_, up)))
784
786
785
787
case tp : TypeAlias =>
786
- val hi = expose(tp.alias, refineCtx, up)
787
- val lo = expose(tp.alias, refineCtx, up)
788
+ val hi = expose(tp.alias, up)
789
+ val lo = expose(tp.alias, up)
788
790
789
791
if (hi =:= lo)
790
792
tp.derivedTypeAlias(hi)
791
793
else
792
794
tp.derivedTypeBounds(lo, hi)
793
795
794
796
case tp @ TypeBounds (lo, hi) =>
795
- tp.derivedTypeBounds(expose(lo, refineCtx, false ), expose(hi, refineCtx , true ))
797
+ tp.derivedTypeBounds(expose(lo, false ), expose(hi, true ))
796
798
797
799
case tp : RefinedType =>
798
800
tp.derivedRefinedType(
799
801
expose(tp.parent),
800
802
tp.refinedName,
801
- expose(tp.refinedInfo, true , up)
803
+ expose(tp.refinedInfo, up)
802
804
)
803
- case tp : TypeProxy if refineCtx =>
805
+ case tp : TypeProxy =>
804
806
tp.underlying match {
805
807
case TypeBounds (lo, hi) =>
806
- expose(if (up) hi else lo, refineCtx, up)
808
+ expose(if (up) hi else lo, up)
807
809
case _ =>
808
810
tp
809
811
}
810
812
811
813
case OrType (tp1, tp2) =>
812
- OrType (expose(tp1, refineCtx, up), expose(tp2, refineCtx , up))
814
+ OrType (expose(tp1, up), expose(tp2, up))
813
815
814
816
case AndType (tp1, tp2) =>
815
- AndType (expose(tp1, refineCtx, up), expose(tp2, refineCtx , up))
817
+ AndType (expose(tp1, up), expose(tp2, up))
816
818
817
819
case _ => tp
818
820
}
0 commit comments