diff --git a/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala b/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala index 6be6ec94c1c3..da94226b34af 100644 --- a/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala +++ b/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala @@ -858,7 +858,8 @@ trait ConstraintHandling { addParamBound(bound) case _ => val pbound = avoidLambdaParams(bound) - kindCompatible(param, pbound) && addBoundTransitively(param, pbound, !fromBelow) + (pbound.isNothingType || kindCompatible(param, pbound)) + && addBoundTransitively(param, pbound, !fromBelow) finally canWidenAbstract = saved addConstraintInvocations -= 1 diff --git a/tests/warn/i19359.scala b/tests/warn/i19359.scala new file mode 100644 index 000000000000..db598a8095e1 --- /dev/null +++ b/tests/warn/i19359.scala @@ -0,0 +1,23 @@ +sealed trait Plan[+E <: Err, +F[+e <: E] <: Fal[e]] + +case class Err() extends Plan[Err, Nothing] +case class Fal[+E <: Err]() extends Plan[E, Fal] +case class Btw[+E <: Err, +F[+e <: E] <: Fal[e]]() extends Plan[E, F] + +class Tests: + def test1(plan: Plan[Err, Nothing]): Unit = plan match + case Err() => + case Btw() => + + def main1 = test1(Btw()) + +/* + +Previously, Plan[Err, Nothing] dropped Btw, +because it didn't instantiate ?F to Nothing + + <== decompose(Plan[Err, Nothing], [Btw[Err, Fal]]) = [Not, Err] + <== decompose(Btw[Err, Fal] & Plan[Err, Nothing]) = [] +<== simplify(Prod(Btw())) = Empty + +*/