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:
+8
-7
@@ -69,16 +69,17 @@ class SwitchOptimizer(private val context: JsGenerationContext, private val last
|
||||
if (constExpr !is IrConst<*>) return false
|
||||
if (!constExpr.isTrueConstant()) return false
|
||||
|
||||
when (branchExpr) {
|
||||
return when (branchExpr) {
|
||||
is IrWhen -> checkForPrimitiveOrPattern(branchExpr, constants)
|
||||
is IrCall -> {
|
||||
val constant = tryToExtractEqeqeqConst(branchExpr) ?: return false
|
||||
constants += constant
|
||||
is IrCall -> when (val constant = tryToExtractEqeqeqConst(branchExpr)) {
|
||||
null -> false
|
||||
else -> {
|
||||
constants += constant
|
||||
true
|
||||
}
|
||||
}
|
||||
else -> return false
|
||||
else -> false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
if (!checkBranchIsOrPattern(thenBranch.result, thenBranch.condition)) return false
|
||||
|
||||
Reference in New Issue
Block a user