From 89dc164b44abb283cb853750488de373a9531f64 Mon Sep 17 00:00:00 2001 From: Yichen Xu Date: Tue, 16 Mar 2021 18:01:34 +0800 Subject: [PATCH 1/2] Fix bound propagation in ConstraintHandling A brief explanation on the problem and the fix: https://gist.github.com/Linyxus/88dcc14087b8940ad992bb78f5f5b1d2 --- .../dotty/tools/dotc/core/ConstraintHandling.scala | 12 ++++++++---- tests/pos/i16682.scala | 8 ++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 tests/pos/i16682.scala diff --git a/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala b/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala index ab6303acd821..0872a4398f9f 100644 --- a/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala +++ b/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala @@ -491,19 +491,23 @@ trait ConstraintHandling { checkPropagated(i"initialized $tl") { constraint = constraint.add(tl, tvars) tl.paramRefs.forall { param => + val lower = constraint.lower(param) + val upper = constraint.upper(param) constraint.entry(param) match { case bounds: TypeBounds => - val lower = constraint.lower(param) - val upper = constraint.upper(param) if lower.nonEmpty && !bounds.lo.isRef(defn.NothingClass) || upper.nonEmpty && !bounds.hi.isAny then constr.println(i"INIT*** $tl") lower.forall(addOneBound(_, bounds.hi, isUpper = true)) && upper.forall(addOneBound(_, bounds.lo, isUpper = false)) - case _ => + case x => // Happens if param was already solved while processing earlier params of the same TypeLambda. // See #4720. - true + + // Should propagate bounds even when param has been solved. + // See #16682. + lower.forall(addOneBound(_, x, isUpper = true)) && + upper.forall(addOneBound(_, x, isUpper = false)) } } } diff --git a/tests/pos/i16682.scala b/tests/pos/i16682.scala new file mode 100644 index 000000000000..47ce64e07858 --- /dev/null +++ b/tests/pos/i16682.scala @@ -0,0 +1,8 @@ +object Test { + final class Tag[T] + + def foo[Z >: Int <: Int, Y >: Z <: Z, X >: Y <: Y, T]: Tag[T] => T = { + case _ : Tag[X] => 0 + } +} + From 7f32760373c70941627d13caadcc92677e5c7fe7 Mon Sep 17 00:00:00 2001 From: Yichen Xu Date: Wed, 17 Mar 2021 18:03:05 +0800 Subject: [PATCH 2/2] Correct issue id: should be #11682 --- compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala | 2 +- tests/pos/{i16682.scala => i11682.scala} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename tests/pos/{i16682.scala => i11682.scala} (100%) diff --git a/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala b/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala index 0872a4398f9f..e9ca12e3db9e 100644 --- a/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala +++ b/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala @@ -505,7 +505,7 @@ trait ConstraintHandling { // See #4720. // Should propagate bounds even when param has been solved. - // See #16682. + // See #11682. lower.forall(addOneBound(_, x, isUpper = true)) && upper.forall(addOneBound(_, x, isUpper = false)) } diff --git a/tests/pos/i16682.scala b/tests/pos/i11682.scala similarity index 100% rename from tests/pos/i16682.scala rename to tests/pos/i11682.scala