@@ -18,22 +18,19 @@ import config.Printers.{constr, typr}
18
18
* By comparison: Constraint handlers are parts of type comparers and can use their functionality.
19
19
* Constraint handlers update the current constraint as a side effect.
20
20
*/
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 . _
23
23
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)
29
26
30
27
implicit def ctx : Context
31
28
32
29
protected def isSubType (tp1 : Type , tp2 : Type ): Boolean
33
30
protected def isSameType (tp1 : Type , tp2 : Type ): Boolean
34
31
35
- protected def constraint : OwnConstraint
36
- protected def constraint_= (c : OwnConstraint ): Unit
32
+ protected def constraint : Constraint
33
+ protected def constraint_= (c : Constraint ): Unit
37
34
38
35
private [this ] var addConstraintInvocations = 0
39
36
@@ -62,10 +59,9 @@ trait ConstraintHandling[VarRef <: TypeVarRef.Of[VarRef, RefBinder], RefBinder <
62
59
* is done only in a temporary way for contexts that may be retracted
63
60
* without also retracting the type var as a whole.
64
61
*/
65
- def instType (tvar : TypeVarHandle [ VarRef ] ): Type = constraint.entry(tvar.origin) match {
62
+ def instType (tvar : TypeVar ): Type = constraint.entry(tvar.origin) match {
66
63
case _ : TypeBounds => NoType
67
- case tp_ if isVarRef(tp_) =>
68
- val tp = tp_.asInstanceOf [VarRef ]
64
+ case tp : VarRef =>
69
65
var tvar1 = constraint.typeVarOfParam(tp)
70
66
if (tvar1.exists) tvar1 else tp
71
67
case tp => tp
@@ -288,9 +284,9 @@ trait ConstraintHandling[VarRef <: TypeVarRef.Of[VarRef, RefBinder], RefBinder <
288
284
case tp : SingletonType => true
289
285
case AndType (tp1, tp2) => isMultiSingleton(tp1) | isMultiSingleton(tp2)
290
286
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)
293
288
case tp : TypeVar => isMultiSingleton(tp.underlying)
289
+ case tp : VarRef => isMultiSingleton(bounds(tp).hi)
294
290
case _ => false
295
291
}
296
292
def isOrType (tp : Type ): Boolean = tp.dealias match {
@@ -331,7 +327,7 @@ trait ConstraintHandling[VarRef <: TypeVarRef.Of[VarRef, RefBinder], RefBinder <
331
327
* Both `c1` and `c2` are required to derive from constraint `pre`, possibly
332
328
* narrowing it with further bounds.
333
329
*/
334
- protected final def subsumes (c1 : OwnConstraint , c2 : OwnConstraint , pre : OwnConstraint ): Boolean =
330
+ protected final def subsumes (c1 : Constraint , c2 : Constraint , pre : Constraint ): Boolean =
335
331
if (c2 eq pre) true
336
332
else if (c1 eq pre) false
337
333
else {
@@ -359,7 +355,7 @@ trait ConstraintHandling[VarRef <: TypeVarRef.Of[VarRef, RefBinder], RefBinder <
359
355
* and propagate all bounds.
360
356
* @param tvars See Constraint#add
361
357
*/
362
- def addToConstraint (tl : RefBinder , tvars : List [TypeVarHandle [ VarRef ] ]): Boolean =
358
+ def addToConstraint (tl : Binder , tvars : List [TypeVar ]): Boolean =
363
359
checkPropagated(i " initialized $tl" ) {
364
360
constraint = constraint.add(tl, tvars)
365
361
tl.boundRefs.forall { param =>
@@ -431,7 +427,7 @@ trait ConstraintHandling[VarRef <: TypeVarRef.Of[VarRef, RefBinder], RefBinder <
431
427
}
432
428
else tp
433
429
434
- def addParamBound (bound : VarRef ) =
430
+ def addParamBound (bound : TypeParamRef ) =
435
431
constraint.entry(param) match {
436
432
case _ : TypeBounds =>
437
433
if (fromBelow) addLess(bound, param) else addLess(param, bound)
@@ -484,10 +480,9 @@ trait ConstraintHandling[VarRef <: TypeVarRef.Of[VarRef, RefBinder], RefBinder <
484
480
val p2 = prune(bound.tp2)
485
481
if (p1.exists && p2.exists) bound.derivedOrType(p1, p2)
486
482
else NoType
487
- case bound : TypeVar if constraint contains bound.origin. asInstanceOf [ VarRef ] =>
483
+ case bound : TypeVar if constraint contains bound.origin =>
488
484
prune(bound.underlying)
489
- case bound_ : TypeParamRef =>
490
- val bound = bound_.asInstanceOf [VarRef ]
485
+ case bound : TypeParamRef =>
491
486
constraint.entry(bound) match {
492
487
case NoType => pruneLambdaParams(bound)
493
488
case _ : TypeBounds =>
@@ -502,8 +497,7 @@ trait ConstraintHandling[VarRef <: TypeVarRef.Of[VarRef, RefBinder], RefBinder <
502
497
}
503
498
504
499
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 =>
507
501
addParamBound(bound)
508
502
case _ =>
509
503
val pbound = prune(bound)
@@ -515,7 +509,7 @@ trait ConstraintHandling[VarRef <: TypeVarRef.Of[VarRef, RefBinder], RefBinder <
515
509
}
516
510
517
511
/** 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 = {
519
513
val saved = constraint
520
514
constraint =
521
515
if (addConstraint(param, tp, fromBelow = true ) &&
0 commit comments