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