Skip to content

Commit 5a081ae

Browse files
committed
Fix scala#4720: support type inference even when
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 scala#4720.
1 parent ddf26ee commit 5a081ae

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -346,13 +346,20 @@ 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 bounds = constraint.nonParamBounds(param)
352+
val lower = constraint.lower(param)
353+
val upper = constraint.upper(param)
354+
if (lower.nonEmpty && !bounds.lo.isRef(defn.NothingClass) ||
355+
upper.nonEmpty && !bounds.hi.isRef(defn.AnyClass)) constr.println(i"INIT*** $tl")
356+
lower.forall(addOneBound(_, bounds.hi, isUpper = true)) &&
357+
upper.forall(addOneBound(_, bounds.lo, isUpper = false))
358+
case _ =>
359+
// Happens if param was already solved while processing earlier params of the same TypeLambda.
360+
// See #4720.
361+
true
362+
}
356363
}
357364
}
358365
}

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)