https://kotlinlang.org logo
y

Yann Badoual

11/14/2020, 8:02 PM
Are returns inside composable currently bugged (alpha07)? I'm getting a lot of
java.lang.IllegalStateException: Start/end imbalance
when using them Wrapping the whole follow code into a conditional block instead fixes the issue
r

romainguy

11/14/2020, 8:10 PM
@Leland Richardson [G]
l

Leland Richardson [G]

11/14/2020, 8:16 PM
We haven’t seen any issues - can you create a simple repro? This could be a runtime issue or a compiler issue
y

Yann Badoual

11/14/2020, 8:43 PM
No problem, will try to do that this weekend
a

Archie

11/17/2020, 9:33 AM
I also encountered this error as well.. I had a composable:
Copy code
@Composable
fun MyComposable(
    myStateList: List<MyState>, 
    ...,
) {
    // ------- This here is causing the error
    val transformedMyState = myStateList.map {
        myTransformation(it)
    }
    // ------- Removing the code above, also removes the error
    LazyRowForIndexed(transformedMyState) {
        ...
    }
}
It was perfectly working on
alpha06
and only encountered the error after migrating to
alpha07
. So in the end I settled to:
Copy code
@Composable
fun MyComposable(
    myStateList: List<MyState>, 
    ...,
) {
    LazyRowForIndexed(
        myStateList.map {
            myTransformation(it)
        }
    ) {
        ...
    }
}
I then no longer get the error... 🤔
l

Leland Richardson [G]

11/18/2020, 12:10 AM
wow, that’s pretty curious
can you file a big with the full code to repro?
based on your observation it seems likely that there’s some compiler related issue here
a

Archie

11/18/2020, 3:57 AM
Will try and recreate it... ill do after work and share the link here...
l

Leland Richardson [G]

11/18/2020, 3:58 AM
thank you
a

Archie

11/18/2020, 1:11 PM
Hi @Leland Richardson [G], I'm unsuccessful in recreating the error.. it seems that the error wasn't cause by the things I mentioned above... hmmm... I would try and backtrack my changes..
y

Yann Badoual

11/19/2020, 2:10 PM
@Leland Richardson [G] Sorry for the delay, I managed to reproduce it with the following minified snippet:
Copy code
@Composable
fun BuggedComposable(
) {
    Surface {
        Box(modifier = Modifier.fillMaxSize()) {
            val state = mutableStateOf<String?>(null)
            val title = state.value ?: return@Box
        }
    }
}
Removing the
?: return@Box
fixes the crash. Do you want me to file a bug with this? (Using alpha07 and kotlin 1.4.0)
(Funny observation, removing the wrapping Box also avoids the crash, so I'm guessing a certain level of nesting is necessary before having the crash?)
l

Leland Richardson [G]

11/19/2020, 5:59 PM
oh, nice. thanks so much for this repro
if you could file a bug that would be great
if not, i can file one on your behalf
y

Yann Badoual

11/19/2020, 6:11 PM
will do
l

Leland Richardson [G]

11/19/2020, 6:23 PM
thank you!
👍 1
y

Yann Badoual

12/21/2020, 6:49 PM
Any news on this @Leland Richardson [G] ?
(Just FYI, still happening on alpha12)
p

Paul Woitaschek

01/24/2023, 4:48 PM
Again happening on 1.4