@@ -46,7 +46,9 @@ object Inferencing {
46
46
/** Instantiate selected type variables `tvars` in type `tp` */
47
47
def instantiateSelected (tp : Type , tvars : List [Type ])(implicit ctx : Context ): Unit =
48
48
if (tvars.nonEmpty)
49
- new IsFullyDefinedAccumulator (new ForceDegree .Value (tvars.contains, minimizeAll = true )).process(tp)
49
+ IsFullyDefinedAccumulator (
50
+ ForceDegree .Value (tvars.contains, allowBottom = false ), minimizeSelected = true
51
+ ).process(tp)
50
52
51
53
/** Instantiate any type variables in `tp` whose bounds contain a reference to
52
54
* one of the parameters in `tparams` or `vparamss`.
@@ -78,19 +80,26 @@ object Inferencing {
78
80
* 2. T is maximized if the constraint over T is only from above (i.e.
79
81
* constrained upper bound != given upper bound and
80
82
* constrained lower bound == given lower bound).
81
- * If (1) and (2) do not apply:
82
- * 3. T is minimized if forceDegree is minimizeAll.
83
- * 4. Otherwise, T is maximized if it appears only contravariantly in the given type,
84
- * or if forceDegree is `noBottom` and T's minimized value is a bottom type.
85
- * 5. Otherwise, T is minimized.
86
83
*
87
- * The instantiation is done in two phases:
84
+ * If (1) and (2) do not apply, and minimizeSelected is set:
85
+ * 3. T is minimized if it has a lower bound (different from Nothing) in the
86
+ * current constraint (the bound might come from T's declaration).
87
+ * 4. Otherwise, T is maximized if it has an upper bound (different from Any)
88
+ * in the currented constraint (the bound might come from T's declaration).
89
+ * 5. Otherwise, T is not instantiated at all.
90
+
91
+ * If (1) and (2) do not apply, and minimizeSelected is not set:
92
+ * 6: T is maximized if it appears only contravariantly in the given type,
93
+ * or if forceDegree is `noBottom` and T has no lower bound different from Nothing.
94
+ * 7. Otherwise, T is minimized.
95
+ *
96
+ * The instantiation for (6) and (7) is done in two phases:
88
97
* 1st Phase: Try to instantiate minimizable type variables to
89
98
* their lower bound. Record whether successful.
90
99
* 2nd Phase: If first phase was successful, instantiate all remaining type variables
91
100
* to their upper bound.
92
101
*/
93
- private class IsFullyDefinedAccumulator (force : ForceDegree .Value , minimizeConstrained : Boolean = false )
102
+ private class IsFullyDefinedAccumulator (force : ForceDegree .Value , minimizeSelected : Boolean = false )
94
103
(implicit ctx : Context ) extends TypeAccumulator [Boolean ] {
95
104
96
105
private def instantiate (tvar : TypeVar , fromBelow : Boolean ): Type = {
@@ -115,15 +124,15 @@ object Inferencing {
115
124
case Contravariant =>
116
125
instantiate(tvar, fromBelow = false )
117
126
case EmptyFlags =>
118
- if force.minimizeAll then
127
+ if minimizeSelected then
119
128
if tvar.hasLowerBound then instantiate(tvar, fromBelow = true )
120
129
else if tvar.hasUpperBound then instantiate(tvar, fromBelow = false )
121
130
else () // hold off instantiating unbounded unconstrained variables
122
131
else if variance >= 0 && (force.allowBottom || tvar.hasLowerBound)
123
132
then instantiate(tvar, fromBelow = true )
124
133
else toMaximize = tvar :: toMaximize
125
134
case VarianceFlags =>
126
- if force.minimizeAll || variance >= 0
135
+ if minimizeSelected || variance >= 0
127
136
then instantiate(tvar, fromBelow = true )
128
137
else toMaximize = tvar :: toMaximize
129
138
foldOver(x, tvar)
@@ -500,9 +509,9 @@ trait Inferencing { this: Typer =>
500
509
501
510
/** An enumeration controlling the degree of forcing in "is-dully-defined" checks. */
502
511
@ sharable object ForceDegree {
503
- class Value (val appliesTo : TypeVar => Boolean , val minimizeAll : Boolean , val allowBottom : Boolean = true )
504
- val none : Value = new Value (_ => false , minimizeAll = false )
505
- val all : Value = new Value (_ => true , minimizeAll = false )
506
- val noBottom : Value = new Value (_ => true , minimizeAll = false , allowBottom = false )
512
+ class Value (val appliesTo : TypeVar => Boolean , val allowBottom : Boolean )
513
+ val none : Value = new Value (_ => false , allowBottom = true )
514
+ val all : Value = new Value (_ => true , allowBottom = true )
515
+ val noBottom : Value = new Value (_ => true , allowBottom = false )
507
516
}
508
517
0 commit comments