Skip to content

Commit adb9aeb

Browse files
committed
Fix simplified logic in isFullyDefinedAccumulator
1 parent a8bd625 commit adb9aeb

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

compiler/src/dotty/tools/dotc/typer/Inferencing.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,10 @@ object Inferencing {
7979
* constrained upper bound != given upper bound and
8080
* constrained lower bound == given lower bound).
8181
* 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.
8486
*
8587
* The instantiation is done in two phases:
8688
* 1st Phase: Try to instantiate minimizable type variables to
@@ -105,12 +107,12 @@ object Inferencing {
105107
if !tvar.isInstantiated && ctx.typerState.constraint.contains(tvar) =>
106108
force.appliesTo(tvar) && {
107109
val pref = tvar.origin
110+
val direction = instDirection(pref)
108111
def avoidBottom =
109112
!force.allowBottom &&
110113
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)
114116
else toMaximize = true
115117
foldOver(x, tvar)
116118
}

0 commit comments

Comments
 (0)