File tree 2 files changed +11
-2
lines changed
compiler/src/dotty/tools/dotc
2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -251,6 +251,11 @@ object Types {
251
251
case _ => false
252
252
}
253
253
254
+ /** Is this type exactly `Any`, or a type lambda ending in `Any`? */
255
+ def isTopOfSomeKind (using Context ): Boolean = dealias match
256
+ case tp : TypeLambda => tp.resType.isTopOfSomeKind
257
+ case _ => isExactlyAny
258
+
254
259
def isBottomType (using Context ): Boolean =
255
260
if ctx.mode.is(Mode .SafeNulls ) && ! ctx.phase.erasedTypes then hasClassSymbol(defn.NothingClass )
256
261
else isBottomTypeAfterErasure
@@ -4896,7 +4901,7 @@ object Types {
4896
4901
def hasLowerBound (using Context ): Boolean = ! currentEntry.loBound.isExactlyNothing
4897
4902
4898
4903
/** For uninstantiated type variables: Is the upper bound different from Any? */
4899
- def hasUpperBound (using Context ): Boolean = ! currentEntry.hiBound.finalResultType.isExactlyAny
4904
+ def hasUpperBound (using Context ): Boolean = ! currentEntry.hiBound.isTopOfSomeKind
4900
4905
4901
4906
/** Unwrap to instance (if instantiated) or origin (if not), until result
4902
4907
* is no longer a TypeVar
Original file line number Diff line number Diff line change @@ -187,7 +187,11 @@ object Inferencing {
187
187
// else hold off instantiating unbounded unconstrained variable
188
188
else if direction != 0 then
189
189
instantiate(tvar, fromBelow = direction < 0 )
190
- else if variance >= 0 && (force.ifBottom == IfBottom .ok && ! tvar.hasUpperBound || tvar.hasLowerBound) then
190
+ else if variance >= 0 && tvar.hasLowerBound then
191
+ instantiate(tvar, fromBelow = true )
192
+ else if (variance > 0 || variance == 0 && ! tvar.hasUpperBound)
193
+ && force.ifBottom == IfBottom .ok
194
+ then // if variance == 0, prefer upper bound if one is given
191
195
instantiate(tvar, fromBelow = true )
192
196
else if variance >= 0 && force.ifBottom == IfBottom .fail then
193
197
fail = true
You can’t perform that action at this time.
0 commit comments