Skip to content

Commit 38135f3

Browse files
committed
Refine minimize condition
1 parent 26576dc commit 38135f3

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3930,6 +3930,10 @@ object Types {
39303930
def hasLowerBound(implicit ctx: Context): Boolean =
39313931
!ctx.typerState.constraint.entry(origin).loBound.isBottomType
39323932

3933+
/** For uninstantiated type variables: Is the upper bound different from Any? */
3934+
def hasUpperBound(implicit ctx: Context): Boolean =
3935+
!ctx.typerState.constraint.entry(origin).hiBound.isRef(defn.AnyClass)
3936+
39333937
/** Unwrap to instance (if instantiated) or origin (if not), until result
39343938
* is no longer a TypeVar
39353939
*/

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ object Inferencing {
111111
def avoidBottom =
112112
!force.allowBottom &&
113113
defn.isBottomType(ctx.typeComparer.approximation(tvar.origin, fromBelow = true))
114-
def preferMin = (force.minimizeAll || variance >= 0) && !avoidBottom
114+
def preferMin =
115+
force.minimizeAll && (!avoidBottom || !tvar.hasUpperBound)
116+
|| variance >= 0 && !avoidBottom
115117
if (direction != 0) instantiate(tvar, direction < 0)
116118
else if (preferMin) instantiate(tvar, fromBelow = true)
117119
else toMaximize = true

tests/neg/undet-classtag.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import scala.reflect.ClassTag
33
object Test {
44
def f[T: reflect.ClassTag](x: T) = ???
55

6-
f(???)
6+
f(???) // error: undetermined ClassTag
77
}
88

99
// SI 9754
@@ -22,6 +22,6 @@ object Program {
2222

2323
// SI 5353
2424
object t5353 {
25-
if (false) Array("qwe") else Array()
25+
if (false) Array("qwe") else Array() // error: undetermined ClassTag
2626
}
2727

0 commit comments

Comments
 (0)