Skip to content

Commit b06d079

Browse files
committed
Fix #4721: don't assert constraints are satisfiable
1 parent d84922b commit b06d079

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

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

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -341,24 +341,22 @@ trait ConstraintHandling {
341341
* and propagate all bounds.
342342
* @param tvars See Constraint#add
343343
*/
344-
def addToConstraint(tl: TypeLambda, tvars: List[TypeVar]): Unit =
345-
assert {
346-
checkPropagated(i"initialized $tl") {
347-
constraint = constraint.add(tl, tvars)
348-
tl.paramRefs.forall { param =>
349-
constraint.entry(param) match {
350-
case bounds: TypeBounds =>
351-
val lower = constraint.lower(param)
352-
val upper = constraint.upper(param)
353-
if (lower.nonEmpty && !bounds.lo.isRef(defn.NothingClass) ||
354-
upper.nonEmpty && !bounds.hi.isRef(defn.AnyClass)) constr.println(i"INIT*** $tl")
355-
lower.forall(addOneBound(_, bounds.hi, isUpper = true)) &&
356-
upper.forall(addOneBound(_, bounds.lo, isUpper = false))
357-
case _ =>
358-
// Happens if param was already solved while processing earlier params of the same TypeLambda.
359-
// See #4720.
360-
true
361-
}
344+
def addToConstraint(tl: TypeLambda, tvars: List[TypeVar]): Boolean =
345+
checkPropagated(i"initialized $tl") {
346+
constraint = constraint.add(tl, tvars)
347+
tl.paramRefs.forall { param =>
348+
constraint.entry(param) match {
349+
case bounds: TypeBounds =>
350+
val lower = constraint.lower(param)
351+
val upper = constraint.upper(param)
352+
if (lower.nonEmpty && !bounds.lo.isRef(defn.NothingClass) ||
353+
upper.nonEmpty && !bounds.hi.isRef(defn.AnyClass)) constr.println(i"INIT*** $tl")
354+
lower.forall(addOneBound(_, bounds.hi, isUpper = true)) &&
355+
upper.forall(addOneBound(_, bounds.lo, isUpper = false))
356+
case _ =>
357+
// Happens if param was already solved while processing earlier params of the same TypeLambda.
358+
// See #4720.
359+
true
362360
}
363361
}
364362
}

tests/neg/i4721.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
object Test {
2+
def main(args: Array[String]):Unit = m(1) // error
3+
def m[Y<:String, Z>:Int, W>:Z<:Y](d:Y):Unit={}
4+
}

tests/neg/i4721a.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
object Test {
2+
def main(args: Array[String]):Unit = m("1") // error
3+
def m[Y<:String, Z>:Int, W>:Z<:Y](d:Y):Unit={}
4+
}

0 commit comments

Comments
 (0)