@@ -18,22 +18,19 @@ import config.Printers.{constr, typr}
1818 * By comparison: Constraint handlers are parts of type comparers and can use their functionality.
1919 * Constraint handlers update the current constraint as a side effect.
2020 */
21- trait ConstraintHandling [ VarRef <: TypeVarRef . Of [ VarRef , RefBinder ], RefBinder <: TypeVarRefBinder . Of [ VarRef , RefBinder ]] {
22- protected final type OwnConstraint = Constraint [ VarRef , RefBinder ]
21+ trait ConstraintHandling {
22+ import Constraint . _
2323
24- protected def isVarRef (r : Type ): Boolean = r.isInstanceOf [TypeVarRef ]
25- protected def isRefBinder (r : Type ): Boolean = r.isInstanceOf [TypeVarRefBinder ]
26-
27- protected def constr_println (msg : => String ): Unit = constr.println(msg)
28- protected def typr_println (msg : => String ): Unit = typr.println(msg)
24+ def constr_println (msg : => String ): Unit = constr.println(msg)
25+ def typr_println (msg : => String ): Unit = typr.println(msg)
2926
3027 implicit def ctx : Context
3128
3229 protected def isSubType (tp1 : Type , tp2 : Type ): Boolean
3330 protected def isSameType (tp1 : Type , tp2 : Type ): Boolean
3431
35- protected def constraint : OwnConstraint
36- protected def constraint_= (c : OwnConstraint ): Unit
32+ protected def constraint : Constraint
33+ protected def constraint_= (c : Constraint ): Unit
3734
3835 private [this ] var addConstraintInvocations = 0
3936
@@ -62,10 +59,9 @@ trait ConstraintHandling[VarRef <: TypeVarRef.Of[VarRef, RefBinder], RefBinder <
6259 * is done only in a temporary way for contexts that may be retracted
6360 * without also retracting the type var as a whole.
6461 */
65- def instType (tvar : TypeVarHandle [ VarRef ] ): Type = constraint.entry(tvar.origin) match {
62+ def instType (tvar : TypeVar ): Type = constraint.entry(tvar.origin) match {
6663 case _ : TypeBounds => NoType
67- case tp_ if isVarRef(tp_) =>
68- val tp = tp_.asInstanceOf [VarRef ]
64+ case tp : VarRef =>
6965 var tvar1 = constraint.typeVarOfParam(tp)
7066 if (tvar1.exists) tvar1 else tp
7167 case tp => tp
@@ -288,9 +284,9 @@ trait ConstraintHandling[VarRef <: TypeVarRef.Of[VarRef, RefBinder], RefBinder <
288284 case tp : SingletonType => true
289285 case AndType (tp1, tp2) => isMultiSingleton(tp1) | isMultiSingleton(tp2)
290286 case OrType (tp1, tp2) => isMultiSingleton(tp1) & isMultiSingleton(tp2)
291- case tp_ if isVarRef(tp_) => isMultiSingleton(bounds(tp_.asInstanceOf [VarRef ]).hi)
292- case tp : TypeRef => isMultiSingleton(tp.info.hiBound)
287+ case tp : TypeRef if ! constraint.contains(tp : VarRef ) => isMultiSingleton(tp.info.hiBound)
293288 case tp : TypeVar => isMultiSingleton(tp.underlying)
289+ case tp : VarRef => isMultiSingleton(bounds(tp).hi)
294290 case _ => false
295291 }
296292 def isOrType (tp : Type ): Boolean = tp.dealias match {
@@ -331,7 +327,7 @@ trait ConstraintHandling[VarRef <: TypeVarRef.Of[VarRef, RefBinder], RefBinder <
331327 * Both `c1` and `c2` are required to derive from constraint `pre`, possibly
332328 * narrowing it with further bounds.
333329 */
334- protected final def subsumes (c1 : OwnConstraint , c2 : OwnConstraint , pre : OwnConstraint ): Boolean =
330+ protected final def subsumes (c1 : Constraint , c2 : Constraint , pre : Constraint ): Boolean =
335331 if (c2 eq pre) true
336332 else if (c1 eq pre) false
337333 else {
@@ -359,7 +355,7 @@ trait ConstraintHandling[VarRef <: TypeVarRef.Of[VarRef, RefBinder], RefBinder <
359355 * and propagate all bounds.
360356 * @param tvars See Constraint#add
361357 */
362- def addToConstraint (tl : RefBinder , tvars : List [TypeVarHandle [ VarRef ] ]): Boolean =
358+ def addToConstraint (tl : Binder , tvars : List [TypeVar ]): Boolean =
363359 checkPropagated(i " initialized $tl" ) {
364360 constraint = constraint.add(tl, tvars)
365361 tl.boundRefs.forall { param =>
@@ -431,7 +427,7 @@ trait ConstraintHandling[VarRef <: TypeVarRef.Of[VarRef, RefBinder], RefBinder <
431427 }
432428 else tp
433429
434- def addParamBound (bound : VarRef ) =
430+ def addParamBound (bound : TypeParamRef ) =
435431 constraint.entry(param) match {
436432 case _ : TypeBounds =>
437433 if (fromBelow) addLess(bound, param) else addLess(param, bound)
@@ -484,10 +480,9 @@ trait ConstraintHandling[VarRef <: TypeVarRef.Of[VarRef, RefBinder], RefBinder <
484480 val p2 = prune(bound.tp2)
485481 if (p1.exists && p2.exists) bound.derivedOrType(p1, p2)
486482 else NoType
487- case bound : TypeVar if constraint contains bound.origin. asInstanceOf [ VarRef ] =>
483+ case bound : TypeVar if constraint contains bound.origin =>
488484 prune(bound.underlying)
489- case bound_ : TypeParamRef =>
490- val bound = bound_.asInstanceOf [VarRef ]
485+ case bound : TypeParamRef =>
491486 constraint.entry(bound) match {
492487 case NoType => pruneLambdaParams(bound)
493488 case _ : TypeBounds =>
@@ -502,8 +497,7 @@ trait ConstraintHandling[VarRef <: TypeVarRef.Of[VarRef, RefBinder], RefBinder <
502497 }
503498
504499 try bound match {
505- case bound_ : TypeParamRef if constraint contains bound_.asInstanceOf [VarRef ] =>
506- val bound = bound_.asInstanceOf [VarRef ]
500+ case bound : TypeParamRef if constraint contains bound =>
507501 addParamBound(bound)
508502 case _ =>
509503 val pbound = prune(bound)
@@ -515,7 +509,7 @@ trait ConstraintHandling[VarRef <: TypeVarRef.Of[VarRef, RefBinder], RefBinder <
515509 }
516510
517511 /** Instantiate `param` to `tp` if the constraint stays satisfiable */
518- protected def tryInstantiate (param : VarRef , tp : Type ): Boolean = {
512+ protected def tryInstantiate (param : TypeParamRef , tp : Type ): Boolean = {
519513 val saved = constraint
520514 constraint =
521515 if (addConstraint(param, tp, fromBelow = true ) &&
0 commit comments