Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow constraining a parameter to Nothing #19397

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

*/
Loading