Skip to content

Commit d84922b

Browse files
committed
Fix #4720: support smarter type inference
Fix regression in eeb5965. A type variable can already be solved in addToConstraint, so don't assume it is unsolved (hence its constraint entry is a TypeBounds) when first processing it. Fix #4720.
1 parent 995a81f commit d84922b

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -346,13 +346,19 @@ trait ConstraintHandling {
346346
checkPropagated(i"initialized $tl") {
347347
constraint = constraint.add(tl, tvars)
348348
tl.paramRefs.forall { param =>
349-
val bounds = constraint.nonParamBounds(param)
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))
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+
}
356362
}
357363
}
358364
}

tests/pos/i4720.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)
3+
def m[Y<:Int, Z>:Int, W>:Z<:Y](d:Y):Unit={}
4+
}

0 commit comments

Comments
 (0)