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