Skip to content

Commit 9aeb139

Browse files
authored
Merge pull request #2435 from dotty-staging/fix-strawman-compile-4
Handle case where typevar instance is fully determined
2 parents d9d5670 + a1aacb9 commit 9aeb139

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
611611
override def toString: String = {
612612
def entryText(tp: Type): String = tp match {
613613
case tp: TypeBounds => tp.toString
614-
case _ =>" := " + tp
614+
case _ => " := " + tp
615615
}
616616
val constrainedText =
617617
" constrained types = " + domainLambdas.mkString("\n")

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,10 @@ object Inferencing {
250250
// val y: List[List[String]] = List(List(1))
251251
if (!hasUnreportedErrors)
252252
vs foreachBinding { (tvar, v) =>
253-
if (v != 0) {
253+
if (v != 0 && ctx.typerState.constraint.contains(tvar)) {
254+
// previous interpolations could have already instantiated `tvar`
255+
// through unification, that's why we have to check again whether `tvar`
256+
// is contained in the current constraint.
254257
typr.println(s"interpolate ${if (v == 1) "co" else "contra"}variant ${tvar.show} in ${tp.show}")
255258
tvar.instantiate(fromBelow = v == 1)
256259
}

tests/pos/strawman-i79.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
object Empty
2+
extends App {
3+
4+
trait Iterable[+A]
5+
extends IterableOnce[A]
6+
7+
trait IterableOps[+A, +CC[X], +C] {
8+
def ++[B >: A](xs: IterableOnce[B]): CC[B] = ???
9+
}
10+
11+
trait IterableOnce[+A]
12+
13+
class LazyList[+A]()
14+
extends IterableOps[A, LazyList, LazyList[A]]
15+
with Iterable[A]
16+
17+
object LazyList {
18+
def empty[A <: Any]: LazyList[A] = new LazyList[A]()
19+
}
20+
21+
LazyList.empty ++ LazyList.empty
22+
}

0 commit comments

Comments
 (0)