Skip to content

Commit

Permalink
Add a test to check that a switch is generated in the bytecode
Browse files Browse the repository at this point in the history
  • Loading branch information
harpocrates committed Mar 29, 2021
1 parent dc2b0b3 commit c78020b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions compiler/test/dotty/tools/backend/jvm/DottyBytecodeTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,28 @@ class TestBCode extends DottyBytecodeTest {
}
}

@Test def switchOnStrings = {
val source =
"""
|object Foo {
| import scala.annotation.switch
| def foo(s: String, b: Boolean) = (s: @switch) match {
| case "AaAa" => println(3)
| case "BBBB" | "c" if b => println(2)
| case "D" | "E" => println(1)
| case _ => println(0)
| }
|}
""".stripMargin

checkBCode(source) { dir =>
val moduleIn = dir.lookupName("Foo$.class", directory = false)
val moduleNode = loadClassNode(moduleIn.input)
val methodNode = getMethod(moduleNode, "foo")
assert(verifySwitch(methodNode))
}
}

@Test def matchWithDefaultNoThrowMatchError = {
val source =
"""class Test {
Expand Down

0 comments on commit c78020b

Please sign in to comment.