Skip to content

Commit c78020b

Browse files
committed
Add a test to check that a switch is generated in the bytecode
1 parent dc2b0b3 commit c78020b

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

compiler/test/dotty/tools/backend/jvm/DottyBytecodeTests.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,28 @@ class TestBCode extends DottyBytecodeTest {
118118
}
119119
}
120120

121+
@Test def switchOnStrings = {
122+
val source =
123+
"""
124+
|object Foo {
125+
| import scala.annotation.switch
126+
| def foo(s: String, b: Boolean) = (s: @switch) match {
127+
| case "AaAa" => println(3)
128+
| case "BBBB" | "c" if b => println(2)
129+
| case "D" | "E" => println(1)
130+
| case _ => println(0)
131+
| }
132+
|}
133+
""".stripMargin
134+
135+
checkBCode(source) { dir =>
136+
val moduleIn = dir.lookupName("Foo$.class", directory = false)
137+
val moduleNode = loadClassNode(moduleIn.input)
138+
val methodNode = getMethod(moduleNode, "foo")
139+
assert(verifySwitch(methodNode))
140+
}
141+
}
142+
121143
@Test def matchWithDefaultNoThrowMatchError = {
122144
val source =
123145
"""class Test {

0 commit comments

Comments
 (0)