Skip to content

Commit 30fa29a

Browse files
committed
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`.
1 parent 11e2526 commit 30fa29a

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-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
}

0 commit comments

Comments
 (0)