Skip to content

Commit 2f91b7b

Browse files
committed
Allow constraining a parameter to Nothing
1 parent dce597f commit 2f91b7b

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,8 @@ trait ConstraintHandling {
858858
addParamBound(bound)
859859
case _ =>
860860
val pbound = avoidLambdaParams(bound)
861-
kindCompatible(param, pbound) && addBoundTransitively(param, pbound, !fromBelow)
861+
(pbound.isNothingType || kindCompatible(param, pbound))
862+
&& addBoundTransitively(param, pbound, !fromBelow)
862863
finally
863864
canWidenAbstract = saved
864865
addConstraintInvocations -= 1

tests/warn/i19359.scala

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
sealed trait Plan[+E <: Err, +F[+e <: E] <: Fal[e]]
2+
3+
case class Err() extends Plan[Err, Nothing]
4+
case class Fal[+E <: Err]() extends Plan[E, Fal]
5+
case class Btw[+E <: Err, +F[+e <: E] <: Fal[e]]() extends Plan[E, F]
6+
7+
class Tests:
8+
def test1(plan: Plan[Err, Nothing]): Unit = plan match
9+
case Err() =>
10+
case Btw() =>
11+
12+
def main1 = test1(Btw())
13+
14+
/*
15+
16+
Previously, Plan[Err, Nothing] dropped Btw,
17+
because it didn't instantiate ?F to Nothing
18+
19+
<== decompose(Plan[Err, Nothing], [Btw[Err, Fal]]) = [Not, Err]
20+
<== decompose(Btw[Err, Fal] & Plan[Err, Nothing]) = []
21+
<== simplify(Prod(Btw())) = Empty
22+
23+
*/

0 commit comments

Comments
 (0)