Skip to content

Commit c2d8874

Browse files
Linyxusmichelou
authored andcommitted
Fix bound propagation in ConstraintHandling
A brief explanation on the problem and the fix: https://gist.github.com/Linyxus/88dcc14087b8940ad992bb78f5f5b1d2
1 parent 1c85471 commit c2d8874

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -491,19 +491,23 @@ trait ConstraintHandling {
491491
checkPropagated(i"initialized $tl") {
492492
constraint = constraint.add(tl, tvars)
493493
tl.paramRefs.forall { param =>
494+
val lower = constraint.lower(param)
495+
val upper = constraint.upper(param)
494496
constraint.entry(param) match {
495497
case bounds: TypeBounds =>
496-
val lower = constraint.lower(param)
497-
val upper = constraint.upper(param)
498498
if lower.nonEmpty && !bounds.lo.isRef(defn.NothingClass)
499499
|| upper.nonEmpty && !bounds.hi.isAny
500500
then constr.println(i"INIT*** $tl")
501501
lower.forall(addOneBound(_, bounds.hi, isUpper = true)) &&
502502
upper.forall(addOneBound(_, bounds.lo, isUpper = false))
503-
case _ =>
503+
case x =>
504504
// Happens if param was already solved while processing earlier params of the same TypeLambda.
505505
// See #4720.
506-
true
506+
507+
// Should propagate bounds even when param has been solved.
508+
// See #16682.
509+
lower.forall(addOneBound(_, x, isUpper = true)) &&
510+
upper.forall(addOneBound(_, x, isUpper = false))
507511
}
508512
}
509513
}

tests/pos/i16682.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
object Test {
2+
final class Tag[T]
3+
4+
def foo[Z >: Int <: Int, Y >: Z <: Z, X >: Y <: Y, T]: Tag[T] => T = {
5+
case _ : Tag[X] => 0
6+
}
7+
}
8+

0 commit comments

Comments
 (0)