Skip to content

Commit 3e89455

Browse files
Test match with sub sub cases and catch with sub cases
1 parent 352317c commit 3e89455

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

tests/pos/sub-sub-match.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import scala.language.experimental.matchWithSubCases
2+
3+
object Test:
4+
val x: Option[Option[Int]] = ???
5+
x match
6+
case Some(x2) with x2 match
7+
case Some(x3) with x3 match
8+
case 1 => "a"
9+
case 2 => "b"
10+
case None => "d"
11+
12+
x match {
13+
case Some(x2) with x2 match {
14+
case Some (x3) with x3 match {
15+
case 1 => "a"
16+
case 2 => "b"
17+
}
18+
}
19+
case None => "d"
20+
}

tests/run/sub-catch.scala

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import scala.language.experimental.matchWithSubCases
2+
3+
enum E extends Exception:
4+
case A(x: Any)
5+
case B(x: Any)
6+
case C
7+
8+
end E
9+
import E.*
10+
11+
def test(op: => Nothing): String =
12+
try op catch
13+
case A(x: Int) if true with x match
14+
case 1 => "A(1)"
15+
case 2 => "A(2)"
16+
case B(x: String) with x match
17+
case "a" => "B(a)"
18+
case "b" => "B(b)"
19+
case _ => "other"
20+
end test
21+
22+
@main def Test =
23+
24+
def check(e: E, r: String): Unit = assert(test(throw e) == r)
25+
26+
check(A(1), "A(1)")
27+
check(A(2), "A(2)")
28+
check(A(3), "other")
29+
check(B("b"), "B(b)")
30+
check(B(1), "other")

0 commit comments

Comments
 (0)