Skip to content

Commit

Permalink
Allow constraining a parameter to Nothing (#19397)
Browse files Browse the repository at this point in the history
Fixes #19359
  • Loading branch information
odersky committed Jan 10, 2024
2 parents 1162b32 + 2f91b7b commit 8039426
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions tests/warn/i19359.scala
Original file line number Diff line number Diff line change
@@ -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
*/

0 comments on commit 8039426

Please sign in to comment.