From 30fa29af777fc43862e79c4a3a1d7736f31d614a Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 15 May 2017 22:07:01 +0200 Subject: [PATCH 1/2] Handle case where typevar instance is fully determined Need another check whether a constraint contains a typevariable before going ahead with instantiating it. Test case in collection strawman: `List.empty ++ List.empty`. --- compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala | 2 +- compiler/src/dotty/tools/dotc/typer/Inferencing.scala | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala b/compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala index 84b0bfc6de46..b83061e8bc35 100644 --- a/compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala +++ b/compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala @@ -611,7 +611,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds, override def toString: String = { def entryText(tp: Type): String = tp match { case tp: TypeBounds => tp.toString - case _ =>" := " + tp + case _ => " := " + tp } val constrainedText = " constrained types = " + domainLambdas.mkString("\n") diff --git a/compiler/src/dotty/tools/dotc/typer/Inferencing.scala b/compiler/src/dotty/tools/dotc/typer/Inferencing.scala index ce656928fbaa..eabd72e434dc 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inferencing.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inferencing.scala @@ -250,7 +250,10 @@ object Inferencing { // val y: List[List[String]] = List(List(1)) if (!hasUnreportedErrors) vs foreachBinding { (tvar, v) => - if (v != 0) { + if (v != 0 && ctx.typerState.constraint.contains(tvar)) { + // previous interpolations could have already instantiated `tvar` + // through unification, that's why we have to check again whether `tvar` + // is contained in the current constraint. typr.println(s"interpolate ${if (v == 1) "co" else "contra"}variant ${tvar.show} in ${tp.show}") tvar.instantiate(fromBelow = v == 1) } From a1aacb99dbf7f61a23dd746546d01da0ed5c549e Mon Sep 17 00:00:00 2001 From: Aggelos Biboudis Date: Tue, 16 May 2017 13:23:45 +0200 Subject: [PATCH 2/2] Add test case --- tests/pos/strawman-i79.scala | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/pos/strawman-i79.scala diff --git a/tests/pos/strawman-i79.scala b/tests/pos/strawman-i79.scala new file mode 100644 index 000000000000..297ab4f46782 --- /dev/null +++ b/tests/pos/strawman-i79.scala @@ -0,0 +1,22 @@ +object Empty + extends App { + + trait Iterable[+A] + extends IterableOnce[A] + + trait IterableOps[+A, +CC[X], +C] { + def ++[B >: A](xs: IterableOnce[B]): CC[B] = ??? + } + + trait IterableOnce[+A] + + class LazyList[+A]() + extends IterableOps[A, LazyList, LazyList[A]] + with Iterable[A] + + object LazyList { + def empty[A <: Any]: LazyList[A] = new LazyList[A]() + } + + LazyList.empty ++ LazyList.empty +}