@@ -79,8 +79,10 @@ object Inferencing {
79
79
* constrained upper bound != given upper bound and
80
80
* constrained lower bound == given lower bound).
81
81
* If (1) and (2) do not apply:
82
- * 3. T is maximized if it appears only contravariantly in the given type.
83
- * 4. T is minimized in all other cases.
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. Otehrwise, T is minimized.
84
86
*
85
87
* The instantiation is done in two phases:
86
88
* 1st Phase: Try to instantiate minimizable type variables to
@@ -105,12 +107,12 @@ object Inferencing {
105
107
if ! tvar.isInstantiated && ctx.typerState.constraint.contains(tvar) =>
106
108
force.appliesTo(tvar) && {
107
109
val pref = tvar.origin
110
+ val direction = instDirection(pref)
108
111
def avoidBottom =
109
112
! force.allowBottom &&
110
113
defn.isBottomType(ctx.typeComparer.approximation(pref, fromBelow = true ))
111
- def preferMax =
112
- instDirection(pref) > 0 || variance >= 0 && avoidBottom
113
- if (force.minimizeAll || ! preferMax) instantiate(tvar, fromBelow = true )
114
+ def preferMin = force.minimizeAll || variance >= 0 && ! avoidBottom
115
+ if (direction < 0 || direction == 0 && preferMin) instantiate(tvar, fromBelow = true )
114
116
else toMaximize = true
115
117
foldOver(x, tvar)
116
118
}
0 commit comments