When by String constants:

Generate TABLESWITCH/LOOKUPSWITCH bytecode operation for when operator by String constants
This commit is contained in:
Denis Zharkov
2014-07-16 20:09:49 +04:00
committed by Evgeny Gerashchenko
parent 5a1c995b5c
commit d4cb822ee8
18 changed files with 511 additions and 75 deletions

View File

@@ -0,0 +1,23 @@
import kotlin.test.assertEquals
fun foo(x : String) : String {
assert("abz]".hashCode() == "aby|".hashCode())
when (x) {
"abz]", "cde" -> return "abz_cde"
"aby|", "ghi", "abz]" -> return "aby_ghi"
}
return "other"
}
fun box() : String {
assertEquals("abz_cde", foo("abz]"))
assertEquals("abz_cde", foo("cde"))
assertEquals("aby_ghi", foo("aby|"))
assertEquals("aby_ghi", foo("ghi"))
assertEquals("other", foo("xyz"))
return "OK"
}