Hey folks, I was playing with Compose over the we...
# compose
s
Hey folks, I was playing with Compose over the weekend, and I tried working with the 
mutableStateOf()
 replacement suggestions for 
@Model
However, when I use a sealed class hierarchy to model my state, e.g like I've done here (https://github.com/segunfamisa/android-zeitung/pull/17/files#diff-03a45e46e60aaa4e3efa4e4e6041dea3R11-R23), I get an exception during IR lowering. The line that stood out for me was: 
Caused by: java.lang.AssertionError: Object should have a primary constructor: ...
I'm wondering if this is a technical limitation worth filing as a FR or bug, or something I totally not should be doing?
l
Can you narrow this down to a minimal repro case? Also if you can paste the full stacktrace that would be good
I can’t imagine why this would have anything to do with mutable state or the compose compiler at all but whether its a bug on the kotlin side or compose side we should narrow it down and get it fixed
m
The only oddity I see is the
@Composable
on the
val
s
The stacktrace is huge, (why I didn't paste it here), but here it is
Yeah, I got a different error about referencing a function (I guess the getter of the val) outside a composable function, but I moved the val directly into the function, to confirm that's not where the problem is. https://kotlinlang.slack.com/archives/CJLTWPH7S/p1593412992211000?thread_ts=1593411552.210300&cid=CJLTWPH7S
I'll try to create a smaller project just with this usecase. Although this project (https://github.com/segunfamisa/android-zeitung/tree/sf/ir-error-with-kotlin-objects) is already small - this is the only screen in the project and the only screen with compose.
Thanks btw, Mon & Leland. I was surprised to read Leland's message on a Sunday night 😮😄
m
Oh,
stringResource
and
vectorResource
are
@Composable
functions so calling them in a constructor is probably why
👍 1
s
Oh I see. You mean that's why it required me to annotate the val, right?
Hmm, and btw, I just tried to repro this on a simple sample to change text colour and I wasn't able to. It seems to work fine with sealed class objects. I guess I'm doing something wrong then. Will investigate again later. Sorry for the false alarm 😄 Probably something wrong with my code.
l
ah i didn’t see those composable calls
that is indeed the problem
but also, this should be an IDE level error when you try it
i just refactored our error reporting so i’m actually pretty confident that this would error out correctly in master, but i’ll double check
👍 2