@@ -811,6 +811,11 @@ object Contexts {
811
811
res
812
812
}
813
813
814
+ def unify (tv : TypeVar , tp : Type ): Unit = {
815
+ gadts.println(i " manually unifying $tv with $tp" )
816
+ constraint = constraint.updateEntry(tv.origin, tp)
817
+ }
818
+
814
819
val symTvar : TypeVar = stripInst(tvar(sym)) match {
815
820
case tv : TypeVar => tv
816
821
case inst =>
@@ -819,37 +824,22 @@ object Contexts {
819
824
return true
820
825
}
821
826
822
- def doAddBound (bound : Type ): Boolean = {
823
- val res = stripInst(bound) match {
824
- case boundTvar : TypeVar =>
825
- if (boundTvar eq symTvar) true
826
- else if (isUpper) addLess(symTvar.origin, boundTvar.origin)
827
- else addLess(boundTvar.origin, symTvar.origin)
828
- case bound =>
829
- if (cautiousSubtype(symTvar, bound, isSubtype = ! isUpper)) { unify(symTvar, bound); true }
830
- else if (isUpper) addUpperBound(symTvar.origin, bound)
831
- else addLowerBound(symTvar.origin, bound)
832
- }
833
-
834
- res
835
- }
836
-
837
- def unify (tv : TypeVar , tp : Type ): Unit = {
838
- gadts.println(i " manually unifying $tv with $tp" )
839
- constraint = constraint.updateEntry(tv.origin, tp)
840
- }
841
-
842
- val tvarBound = (new TypeVarInsertingMap ()(ctx))(bound)
843
- val res = tvarBound match {
827
+ val internalizedBound = (new TypeVarInsertingMap ()(ctx))(bound)
828
+ val res = stripInst(internalizedBound) match {
844
829
case boundTvar : TypeVar =>
845
- doAddBound(boundTvar)
846
- case tp => doAddBound(tp)
830
+ if (boundTvar eq symTvar) true
831
+ else if (isUpper) addLess(symTvar.origin, boundTvar.origin)
832
+ else addLess(boundTvar.origin, symTvar.origin)
833
+ case bound =>
834
+ if (cautiousSubtype(symTvar, bound, isSubtype = ! isUpper)) { unify(symTvar, bound); true }
835
+ else if (isUpper) addUpperBound(symTvar.origin, bound)
836
+ else addLowerBound(symTvar.origin, bound)
847
837
}
848
838
849
839
gadts.println {
850
840
val descr = if (isUpper) " upper" else " lower"
851
841
val op = if (isUpper) " <:" else " >:"
852
- i " adding $descr bound $sym $op $bound = $res\t ( $symTvar $op $tvarBound ) "
842
+ i " adding $descr bound $sym $op $bound = $res\t ( $symTvar $op $internalizedBound ) "
853
843
}
854
844
res
855
845
} finally checkInProgress = false
0 commit comments