@@ -19,6 +19,7 @@ import config.Printers.{constr, typr}
19
19
* Constraint handlers update the current constraint as a side effect.
20
20
*/
21
21
trait ConstraintHandling {
22
+ import Constraint ._
22
23
23
24
def constr_println (msg : => String ): Unit = constr.println(msg)
24
25
def typr_println (msg : => String ): Unit = typr.println(msg)
@@ -60,13 +61,13 @@ trait ConstraintHandling {
60
61
*/
61
62
def instType (tvar : TypeVar ): Type = constraint.entry(tvar.origin) match {
62
63
case _ : TypeBounds => NoType
63
- case tp : TypeParamRef =>
64
+ case tp : VarRef =>
64
65
var tvar1 = constraint.typeVarOfParam(tp)
65
66
if (tvar1.exists) tvar1 else tp
66
67
case tp => tp
67
68
}
68
69
69
- protected def addOneBound (param : TypeParamRef , bound : Type , isUpper : Boolean ): Boolean =
70
+ protected def addOneBound (param : VarRef , bound : Type , isUpper : Boolean ): Boolean =
70
71
! constraint.contains(param) || {
71
72
def occursIn (bound : Type ): Boolean = {
72
73
val b = bound.dealias
@@ -84,7 +85,7 @@ trait ConstraintHandling {
84
85
assert(! occursIn(bound), s " $param occurs in $bound" )
85
86
86
87
val oldBounds @ TypeBounds (lo, hi) = constraint.nonParamBounds(param)
87
- val equalBounds = isUpper && (lo eq bound ) || ! isUpper && (bound eq hi)
88
+ val equalBounds = isUpper && (bound eq lo ) || ! isUpper && (bound eq hi)
88
89
if (equalBounds && ! bound.existsPart(_.isInstanceOf [WildcardType ])) {
89
90
// The narrowed bounds are equal and do not contain wildcards,
90
91
// so we can remove `param` from the constraint.
@@ -116,7 +117,7 @@ trait ConstraintHandling {
116
117
117
118
private def location (implicit ctx : Context ) = " " // i"in ${ctx.typerState.stateChainStr}" // use for debugging
118
119
119
- protected def addUpperBound (param : TypeParamRef , bound : Type ): Boolean = {
120
+ protected def addUpperBound (param : VarRef , bound : Type ): Boolean = {
120
121
def description = i " constraint $param <: $bound to \n $constraint"
121
122
if (bound.isRef(defn.NothingClass ) && ctx.typerState.isGlobalCommittable) {
122
123
def msg = s " !!! instantiated to Nothing: $param, constraint = ${constraint.show}"
@@ -132,7 +133,7 @@ trait ConstraintHandling {
132
133
res
133
134
}
134
135
135
- protected def addLowerBound (param : TypeParamRef , bound : Type ): Boolean = {
136
+ protected def addLowerBound (param : VarRef , bound : Type ): Boolean = {
136
137
def description = i " constraint $param >: $bound to \n $constraint"
137
138
constr_println(i " adding $description" )
138
139
val upper = constraint.upper(param)
@@ -143,7 +144,7 @@ trait ConstraintHandling {
143
144
res
144
145
}
145
146
146
- protected def addLess (p1 : TypeParamRef , p2 : TypeParamRef ): Boolean = {
147
+ protected def addLess (p1 : VarRef , p2 : VarRef ): Boolean = {
147
148
def description = i " ordering $p1 <: $p2 to \n $constraint"
148
149
val res =
149
150
if (constraint.isLess(p2, p1)) unify(p2, p1)
@@ -165,7 +166,7 @@ trait ConstraintHandling {
165
166
/** Make p2 = p1, transfer all bounds of p2 to p1
166
167
* @pre less(p1)(p2)
167
168
*/
168
- private def unify (p1 : TypeParamRef , p2 : TypeParamRef ): Boolean = {
169
+ private def unify (p1 : VarRef , p2 : VarRef ): Boolean = {
169
170
constr_println(s " unifying $p1 $p2" )
170
171
assert(constraint.isLess(p1, p2))
171
172
val down = constraint.exclusiveLower(p2, p1)
@@ -224,7 +225,7 @@ trait ConstraintHandling {
224
225
* @return the instantiating type
225
226
* @pre `param` is in the constraint's domain.
226
227
*/
227
- final def approximation (param : TypeParamRef , fromBelow : Boolean ): Type = {
228
+ final def approximation (param : VarRef , fromBelow : Boolean ): Type = {
228
229
val avoidParam = new TypeMap {
229
230
override def stopAtStatic = true
230
231
def avoidInArg (arg : Type ): Type =
@@ -283,9 +284,9 @@ trait ConstraintHandling {
283
284
case tp : SingletonType => true
284
285
case AndType (tp1, tp2) => isMultiSingleton(tp1) | isMultiSingleton(tp2)
285
286
case OrType (tp1, tp2) => isMultiSingleton(tp1) & isMultiSingleton(tp2)
286
- case tp : TypeRef => isMultiSingleton(tp.info.hiBound)
287
+ case tp : TypeRef if ! constraint.contains( tp : VarRef ) => isMultiSingleton(tp.info.hiBound)
287
288
case tp : TypeVar => isMultiSingleton(tp.underlying)
288
- case tp : TypeParamRef => isMultiSingleton(bounds(tp).hi)
289
+ case tp : VarRef => isMultiSingleton(bounds(tp).hi)
289
290
case _ => false
290
291
}
291
292
def isOrType (tp : Type ): Boolean = tp.dealias match {
@@ -311,7 +312,7 @@ trait ConstraintHandling {
311
312
* a lower bound instantiation can be a singleton type only if the upper bound
312
313
* is also a singleton type.
313
314
*/
314
- def instanceType (param : TypeParamRef , fromBelow : Boolean ): Type = {
315
+ def instanceType (param : VarRef , fromBelow : Boolean ): Type = {
315
316
val inst = approximation(param, fromBelow).simplified
316
317
if (fromBelow) widenInferred(inst, constraint.fullUpperBound(param)) else inst
317
318
}
@@ -340,12 +341,12 @@ trait ConstraintHandling {
340
341
}
341
342
342
343
/** The current bounds of type parameter `param` */
343
- def bounds (param : TypeParamRef ): TypeBounds = {
344
+ def bounds (param : VarRef ): TypeBounds = {
344
345
val e = constraint.entry(param)
345
346
if (e.exists) e.bounds
346
347
else {
347
- val pinfos = param.binder.paramInfos
348
- if (pinfos != null ) pinfos(param.paramNum ) // pinfos == null happens in pos/i536.scala
348
+ val pinfos = param.binder.refInfos
349
+ if (pinfos != null ) pinfos(param.refNum ) // pinfos == null happens in pos/i536.scala
349
350
else TypeBounds .empty
350
351
}
351
352
}
@@ -354,10 +355,10 @@ trait ConstraintHandling {
354
355
* and propagate all bounds.
355
356
* @param tvars See Constraint#add
356
357
*/
357
- def addToConstraint (tl : TypeLambda , tvars : List [TypeVar ]): Boolean =
358
+ def addToConstraint (tl : Binder , tvars : List [TypeVar ]): Boolean =
358
359
checkPropagated(i " initialized $tl" ) {
359
360
constraint = constraint.add(tl, tvars)
360
- tl.paramRefs .forall { param =>
361
+ tl.boundRefs .forall { param =>
361
362
constraint.entry(param) match {
362
363
case bounds : TypeBounds =>
363
364
val lower = constraint.lower(param)
@@ -375,14 +376,14 @@ trait ConstraintHandling {
375
376
}
376
377
377
378
/** Can `param` be constrained with new bounds? */
378
- final def canConstrain (param : TypeParamRef ): Boolean =
379
+ final def canConstrain (param : VarRef ): Boolean =
379
380
(! frozenConstraint || (caseLambda `eq` param.binder)) && constraint.contains(param)
380
381
381
382
/** Is `param` assumed to be a sub- and super-type of any other type?
382
383
* This holds if `TypeVarsMissContext` is set unless `param` is a part
383
384
* of a MatchType that is currently normalized.
384
385
*/
385
- final def assumedTrue (param : TypeParamRef ): Boolean =
386
+ final def assumedTrue (param : VarRef ): Boolean =
386
387
ctx.mode.is(Mode .TypevarsMissContext ) && (caseLambda `ne` param.binder)
387
388
388
389
/** Add constraint `param <: bound` if `fromBelow` is false, `param >: bound` otherwise.
@@ -392,7 +393,7 @@ trait ConstraintHandling {
392
393
* not be AndTypes and lower bounds may not be OrTypes. This is assured by the
393
394
* way isSubType is organized.
394
395
*/
395
- protected def addConstraint (param : TypeParamRef , bound : Type , fromBelow : Boolean ): Boolean = {
396
+ protected def addConstraint (param : VarRef , bound : Type , fromBelow : Boolean ): Boolean = {
396
397
def description = i " constr $param ${if (fromBelow) " >:" else " <:" } $bound: \n $constraint"
397
398
// checkPropagated(s"adding $description")(true) // DEBUG in case following fails
398
399
checkPropagated(s " added $description" ) {
@@ -522,7 +523,7 @@ trait ConstraintHandling {
522
523
if (Config .checkConstraintsPropagated && result && addConstraintInvocations == 0 ) {
523
524
inFrozenConstraint {
524
525
for (p <- constraint.domainParams) {
525
- def check (cond : => Boolean , q : TypeParamRef , ordering : String , explanation : String ): Unit =
526
+ def check (cond : => Boolean , q : VarRef , ordering : String , explanation : String ): Unit =
526
527
assert(cond, i " propagation failure for $p $ordering $q: $explanation\n $msg" )
527
528
for (u <- constraint.upper(p))
528
529
check(bounds(p).hi <:< bounds(u).hi, u, " <:" , " upper bound not propagated" )
0 commit comments