Status Update
Comments
je...@google.com <je...@google.com>
as...@google.com <as...@google.com> #2
What is the false positive here? Is there a lint inspection that triggers here?
be...@google.com <be...@google.com> #3
Apologies, bad bug report.
ProduceStateDoesNotAssignValue
is the lint check, it is saying the above snippet does not assign a value inside produceState
but it clearly does.
be...@ridewithvia.com <be...@ridewithvia.com> #4
We see this with AGP 8.6(.1) - it doesn't appear with the latest Compose and AGP 8.5.2
It doesn't trigger if the produceState has no key
s, but does as soon as it does have one or more. I've attached a simple reproducer project - running ./gradlew lintDebug
fails.
lp...@google.com <lp...@google.com>
lp...@google.com <lp...@google.com> #5
I can reproduce with the sample project in
This is a different issue to before - for the following:
val state = produceState("No-one", key1 = Unit) {
value = "Bob"
}
The lint code:
// The ProduceStateScope lambda
val producer = node.valueArguments.find { node.getParameterForArgument(it)?.name == "producer" } ?: return
Is no longer getting the lambda, but for some reason it thinks the argument Unit
resolves to the parameter with name "producer". I'm not sure what changed here, but this seems wrong... Jinseong, do you have any ideas here on what might have changed here from? If I change back to Kotlin 1.9.20 then it correctly resolves to the lambda parameter.
I can of course update the lint logic here to do something different, but it should be a bug that the parameter "producer" is resolved to the incorrect argument
lp...@google.com <lp...@google.com> #6
(I think part of the reason this logic might get confused is because in bytecode this method has the compose compiler generated parameters for $composer and $changed, whereas these don't exist in source, but I don't see what changed in this space between 1.9.20 and 2.0.20)
js...@google.com <js...@google.com> #7
I don't see what changed in this space between 1.9.20 and 2.0.20
One major change between two is whether K2 Lint is used by default or not, and I remember there was/is an issue about binary resolution, in particular, when there are synthetic parameters generated by Compose compiler plugin. I'm not entirely sure it's properly addressed at that time or it still remains.
js...@google.com <js...@google.com> #8
I remember there was/is an issue about binary resolution, in particular, when there are synthetic parameters generated by Compose compiler plugin.
I meant this one:
js...@google.com <js...@google.com> #9
As a note, reproduced (thanks!):
.../ComposeLint86/ComposeLint86/app/src/main/java/com/example/composelint86/MainActivity.kt:35: Error: produceState calls should assign value inside the producer lambda [ProduceStateDoesNotAssignValue from androidx.compose.runtime]
val state = produceState("No-one", key1 = Unit) {
~~~~~~~~~~~~
Explanation for issues of type "ProduceStateDoesNotAssignValue":
produceState returns an observable State using values assigned inside the
producer lambda. If the lambda never assigns (i.e value = foo), then the
State will never change. Make sure to assign a value when the source you
are producing values from changes / emits a new value. For sample usage see
the produceState documentation.
Vendor: Jetpack Compose
Identifier: androidx.compose.runtime
It's supposed to be:
@Composable
fun <T> produceState(
initialValue: T,
key1: Any?,
producer: suspend ProduceStateScope<T>.() -> Unit
): State<T> { ... }
but resolved to:
@Composable
fun <T> produceState(
initialValue: T,
producer: suspend ProduceStateScope<T>.() -> Unit
): State<T> { ... }
js...@google.com <js...@google.com> #10
FYI, another instance of wrong resolution:
Description
Jetpack Compose version: 2024.09.02
Upgrading from 2024.09.00 to 02 has triggered a false positive on the following snippet with
produceState