Fixed
Status Update
Comments
al...@google.com <al...@google.com>
as...@google.com <as...@google.com> #3
It seems like the fix above broke bytecode codegen for some conditions. Test:
@Test
fun test_groupAroundIfComposeCallInIfConditionWithShortCircuit() = testCompile(
source = """
import androidx.compose.runtime.*
@Composable
fun Test() {
ReceiveValue(if (getCondition()) 0 else 1)
ReceiveValue(if (state && getCondition()) 0 else 1)
ReceiveValue(if (getCondition() && state) 0 else 1)
ReceiveValue(if (getCondition() || state) 0 else 1)
ReceiveValue(if (state || getCondition()) 0 else 1)
}
val state by mutableStateOf(true)
@Composable
fun getCondition() = remember { mutableStateOf(false) }.value
@Composable
fun ReceiveValue(value: Int) { }
"""
)
Description
[With nonSkippingGroupOptimization feature enabled]
The following code,
does not produce a group around the
if
statement.This code produces,
but should produce,
A non-unit returning function, like
remember
cannot be conditionally called in a group. That is, if the group executes, it must execute in a group that always exists if it is called and is removed when it isn't.Without this group, the runtime will only detect that new content is being inserted into composition when the
Wrap
function is called. It currently will record the newremember
calls but gets confused about what order to send theonRemember
andonForgotten
calls.