Skip to content

Commit 682a596

Browse files
committed
Update test (thanks to @kevin-lee)
1 parent a84e970 commit 682a596

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

tests/patmat/i12337.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
8: Pattern Match Exhaustivity: Foo(Inactive)
2+
17: Pattern Match Exhaustivity: Foo(Status.Active(_))

tests/patmat/i12337.scala

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
sealed trait Status
22
object Status {
3-
case object Active extends Status
3+
case class Active(since: Int) extends Status
44
case object Inactive extends Status
55
}
66

77
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")
1211
}
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 {

0 commit comments

Comments
 (0)