Skip to content

Commit 2460f96

Browse files
committed
Always minimize type variables when interpolating an expected type of an implicit.
This was suggested in #878.
1 parent 0514d0e commit 2460f96

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/dotty/tools/dotc/transform/PatternMatcher.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1611,7 +1611,7 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans
16111611
// (otherwise equality is required)
16121612
def compareOp: (Tree, Tree) => Tree =
16131613
if (aligner.isStar) _.select(defn.Int_>=).appliedTo(_)
1614-
else _.select(defn.Int_==).appliedTo(_)
1614+
else _.select(defn.Int_==).appliedTo(_)
16151615

16161616
// `if (binder != null && $checkExpectedLength [== | >=] 0) then else zero`
16171617
(seqTree(binder).select(defn.Any_!=).appliedTo(Literal(Constant(null)))).select(defn.Boolean_&&).appliedTo(compareOp(checkExpectedLength, Literal(Constant(0))))

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ object Inferencing {
4646

4747
/** Instantiate selected type variables `tvars` in type `tp` */
4848
def instantiateSelected(tp: Type, tvars: List[Type])(implicit ctx: Context): Unit =
49-
new IsFullyDefinedAccumulator(new ForceDegree.Value(tvars.contains)).process(tp)
49+
new IsFullyDefinedAccumulator(new ForceDegree.Value(tvars.contains, minimizeAll = true)).process(tp)
5050

5151
/** The accumulator which forces type variables using the policy encoded in `force`
5252
* and returns whether the type is fully defined. The direction in which
@@ -81,11 +81,12 @@ object Inferencing {
8181
force.appliesTo(tvar) && {
8282
val direction = instDirection(tvar.origin)
8383
if (direction != 0) {
84-
//if (direction > 0) println(s"inst $tvar dir = up")
84+
if (direction > 0) println(s"inst $tvar dir = up")
8585
instantiate(tvar, direction < 0)
8686
}
8787
else {
8888
val minimize =
89+
force.minimizeAll ||
8990
variance >= 0 && !(
9091
force == ForceDegree.noBottom &&
9192
defn.isBottomType(ctx.typeComparer.approximation(tvar.origin, fromBelow = true)))
@@ -293,9 +294,9 @@ object Inferencing {
293294

294295
/** An enumeration controlling the degree of forcing in "is-dully-defined" checks. */
295296
@sharable object ForceDegree {
296-
class Value(val appliesTo: TypeVar => Boolean)
297-
val none = new Value(_ => false)
298-
val all = new Value(_ => true)
299-
val noBottom = new Value(_ => true)
297+
class Value(val appliesTo: TypeVar => Boolean, val minimizeAll: Boolean)
298+
val none = new Value(_ => false, minimizeAll = false)
299+
val all = new Value(_ => true, minimizeAll = false)
300+
val noBottom = new Value(_ => true, minimizeAll = false)
300301
}
301302

0 commit comments

Comments
 (0)