File tree 2 files changed +20
-5
lines changed
2 files changed +20
-5
lines changed Original file line number Diff line number Diff line change 1
1
8: Pattern Match Exhaustivity: Foo(Inactive)
2
+ 17: Pattern Match Exhaustivity: Foo(Status.Active(_))
Original file line number Diff line number Diff line change 1
1
sealed trait Status
2
2
object Status {
3
- case object Active extends Status
3
+ case class Active ( since : Int ) extends Status
4
4
case object Inactive extends Status
5
5
}
6
6
7
7
case class Foo (status : Status )
8
- def bar (user : Foo ): Unit = user match {
9
- case Foo (Status .Active ) =>
10
- println(" active" )
11
- // no compile-time warning for missing Status.Inactive case
8
+ def bar (foo : Foo ): Unit = foo match {
9
+ case Foo (Status .Active (since)) =>
10
+ println(s " active since $since" )
12
11
}
12
+ // Expected:
13
+ // warning: match may not be exhaustive.
14
+ // It would fail on the following input: Foo(Inactive)
15
+ // def bar(foo: Foo): Unit = foo match {
16
+
17
+ def baz (foo : Foo ): Unit = foo match {
18
+ case Foo (Status .Active (2000 )) =>
19
+ println(" active since 2000" )
20
+ case Foo (Status .Inactive ) =>
21
+ println(" inactive" )
22
+ }
23
+ // Expected:
24
+ // warning: match may not be exhaustive.
25
+ // It would fail on the following input: Foo(Active((x: Int forSome x not in 2000)))
26
+ // def baz(foo: Foo): Unit = foo match {
You can’t perform that action at this time.
0 commit comments