@@ -746,7 +746,7 @@ object Contexts {
746
746
747
747
private [this ] var checkInProgress = false
748
748
749
- // TODO: dirty kludge - should this class be an inner class of TyperState instead?
749
+ // TODO: clean up this dirty kludge
750
750
private [this ] var myCtx : Context = null
751
751
implicit override def ctx = myCtx
752
752
@ forceInline private [this ] final def inCtx [T ](_ctx : Context )(op : => T ) = {
@@ -769,8 +769,8 @@ object Contexts {
769
769
val res = {
770
770
import NameKinds .DepParamName
771
771
// avoid registering the TypeVar with TyperState / TyperState#constraint
772
- // TyperState TypeVars get instantiated when we don't want them to (see pos/i3500.scala)
773
- // TyperState#constraint TypeVars can be narrowed in subtype checks - don't want that either
772
+ // - we don't want TyperState instantiating these TypeVars
773
+ // - we don't want TypeComparer constraining these TypeVars
774
774
val poly = PolyType (DepParamName .fresh(sym.name.toTypeName) :: Nil )(
775
775
pt => TypeBounds .empty :: Nil ,
776
776
pt => defn.AnyType )
@@ -796,27 +796,22 @@ object Contexts {
796
796
case _ => tp
797
797
}
798
798
799
- def cautiousSubtype (tp1 : Type , tp2 : Type , isSubtype : Boolean , allowNarrowing : Boolean = false ): Boolean = {
799
+ def cautiousSubtype (tp1 : Type , tp2 : Type , isSubtype : Boolean ): Boolean = {
800
800
val externalizedTp1 = (new TypeVarRemovingMap )(tp1)
801
801
val externalizedTp2 = (new TypeVarRemovingMap )(tp2)
802
802
803
803
def descr = {
804
804
def op = s " frozen_ ${if (isSubtype) " <:<" else " >:>" }"
805
- def flex = s " GADTFlexible= $allowNarrowing"
806
- i " $tp1 $op $tp2\n\t $externalizedTp1 $op $externalizedTp2 ( $flex) "
805
+ i " $tp1 $op $tp2\n\t $externalizedTp1 $op $externalizedTp2"
807
806
}
808
807
// gadts.println(descr)
809
808
810
- val outerCtx = ctx
811
- val res = {
812
- // implicit val ctx : Context =
813
- // if (allowNarrowing) outerCtx else outerCtx.fresh.retractMode(Mode.GADTflexible)
814
-
809
+ val res =
815
810
// TypeComparer.explain[Boolean](gadts.println) { implicit ctx =>
816
- if (isSubtype) externalizedTp1 frozen_<:< externalizedTp2
811
+ if (isSubtype) externalizedTp1 frozen_<:< externalizedTp2
817
812
else externalizedTp2 frozen_<:< externalizedTp1
818
813
// }
819
- }
814
+
820
815
gadts.println(i " $descr = $res" )
821
816
res
822
817
}
@@ -825,8 +820,8 @@ object Contexts {
825
820
case tv : TypeVar => tv
826
821
case inst =>
827
822
gadts.println(i " instantiated: $sym -> $inst" )
828
- // return true
829
- return cautiousSubtype(inst, bound, isSubtype = isUpper, allowNarrowing = true )
823
+ // this is wrong in general, but "correct" due to a subtype check in TypeComparer#narrowGadtBounds
824
+ return true
830
825
}
831
826
832
827
def doAddBound (bound : Type ): Boolean = {
@@ -873,7 +868,6 @@ object Contexts {
873
868
(new TypeVarRemovingMap )(tb).asInstanceOf [TypeBounds ]
874
869
}
875
870
val res =
876
- // retrieveBounds
877
871
if (checkInProgress || ctx.mode.is(Mode .GADTflexible )) retrieveBounds
878
872
else {
879
873
if (dirtyFlag) {
@@ -882,8 +876,7 @@ object Contexts {
882
876
boundCache = SimpleIdentityMap .Empty .updated(sym, bounds)
883
877
bounds
884
878
} else boundCache(sym) match {
885
- case tb : TypeBounds =>
886
- tb
879
+ case tb : TypeBounds => tb
887
880
case null =>
888
881
val bounds = retrieveBounds
889
882
boundCache = boundCache.updated(sym, bounds)
0 commit comments