Skip to content

Commit c252ffd

Browse files
committed
Fix #7877: Refine instantiation criterion before implicit search
Refine criterion when to instantiate before implicit search. Don' instantiate typevars that are completely unconstrained. Rely instead on resolving these typevars by the implicit search.
1 parent e81d0a8 commit c252ffd

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ object Inferencing {
112112
force.minimizeAll && (tvar.hasLowerBound || !tvar.hasUpperBound)
113113
|| variance >= 0 && (force.allowBottom || tvar.hasLowerBound)
114114
if (direction != 0) instantiate(tvar, direction < 0)
115-
else if (preferMin) instantiate(tvar, fromBelow = true)
115+
else if (preferMin)
116+
if force.minimizeAll && !tvar.hasLowerBound then () // do nothing
117+
else instantiate(tvar, fromBelow = true)
116118
else toMaximize = tvar :: toMaximize
117119
foldOver(x, tvar)
118120
}

tests/pos/i7877.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
object Example extends App {
2+
3+
trait ZSink[-R, +E, +A0, -A, +B] {
4+
def orElse[R1 <: R, E1, A00 >: A0, A1 <: A, C](
5+
that: ZSink[R1, E1, A00, A1, C]
6+
)(implicit ev: A1 =:= A00): ZSink[R1, E1, A00, A1, Either[B, C]] =
7+
???
8+
}
9+
10+
object ZSink {
11+
def identity[A]: ZSink[Any, Unit, Nothing, A, A] = ???
12+
def fail[E](e: E): ZSink[Any, E, Nothing, Any, Nothing] = ???
13+
}
14+
15+
// compiles
16+
val a: ZSink[Any, String, Int, Int, Either[Int, Nothing]] =
17+
ZSink.identity[Int].orElse(ZSink.fail("Ouch"))
18+
19+
// cannot prove that Int =:= Nothing
20+
ZSink.identity[Int].orElse(ZSink.fail("Ouch"))
21+
}

0 commit comments

Comments
 (0)