KJS IR: Fix KT-45738 - Consider recursive checkForPrimitiveOrPattern
Recursive results from checkForPrimitiveOrPattern were ignored. If it found a case/condition that could not be optimized the resulting "false" was not propagated. This would lead to a "optimized" when without all conditions. - see KT-45738 - The return is now lifted out of the when to make it more obvious what is going on. - New test for mixed multiple conditions in when
This commit is contained in:
+21
@@ -0,0 +1,21 @@
|
||||
private fun parse(text: String) = when (text) {
|
||||
Numbers.One.name, "one", "1" -> 1
|
||||
Numbers.Two.name, "two", "2" -> 2
|
||||
else -> -1
|
||||
}
|
||||
|
||||
enum class Numbers {
|
||||
One,
|
||||
Two,
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
|
||||
val oneParsed = parse("one")
|
||||
if (oneParsed != 1) return "'one' should map to '1' but was $oneParsed"
|
||||
|
||||
val OneParsed = parse("One")
|
||||
if (OneParsed != 1) return "'One' should map to '1' but was $OneParsed"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user