Skip to content

Commit 556dc8c

Browse files
committed
Added a test-case for switches with Yvirtpatmat.
Added a bunch of tests that cover changes related to switches that were applied to Yvirtpatmat implementation. Note: I didn't add those tests progressively because my changes fix trees after typer phase but do not affect resulting bytecode. How come? It's because -Yvirtpatmat will emit pattern for switches and then the old pattern matcher implementation would transform them in the old fashion in explicitouter. We cannot disable the old pattern matcher in explicitouter yet because it doesn't handle patterns used for catching exceptions. Thus, consider this as a sign of the fact that Yvirtpatmat is still work in progress.
1 parent 39457f6 commit 556dc8c

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
zero
2+
one
3+
many
4+
got a
5+
got b
6+
got some letter
7+
scala.MatchError: 5 (of class java.lang.Integer)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-Yvirtpatmat -Xexperimental
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
object Test extends App {
2+
def intSwitch(x: Int) = x match {
3+
case 0 => "zero"
4+
case 1 => "one"
5+
case _ => "many"
6+
}
7+
8+
println(intSwitch(0))
9+
println(intSwitch(1))
10+
println(intSwitch(10))
11+
12+
def charSwitch(x: Char) = x match {
13+
case 'a' => "got a"
14+
case 'b' => "got b"
15+
case _ => "got some letter"
16+
}
17+
18+
println(charSwitch('a'))
19+
println(charSwitch('b'))
20+
println(charSwitch('z'))
21+
22+
def implicitDefault(x: Int) = x match {
23+
case 0 => 0
24+
}
25+
26+
try {
27+
implicitDefault(5)
28+
} catch {
29+
case e: MatchError => println(e)
30+
}
31+
32+
}

0 commit comments

Comments
 (0)