https://kotlinlang.org logo
#compose
Title
# compose
s

SrSouza

03/24/2022, 2:34 AM
Hi folks, I'm trying to create a delegate function that is a
@Composable
no problem problem building it. but I'm having runtime exception:
java.lang.NoSuchMethodError: No virtual method getValue-0d7_KjU(Ljava/lang/Object;Lkotlin/reflect/KProperty;)J
Does
@Composable
support delegate property? Example:
Copy code
@Composable
public operator fun getValue(thisRef: Any?, property: KProperty<*>): Color {
    return animateColorAsState(targetValue = state).value
}
r

Ronald Wolvers

03/24/2022, 7:05 AM
Good morning @SrSouza! Although I cannot say why that exception is being thrown, I was wondering where you are using this delegate. Are you calling it from within another
@Composable
? I have not seen composable functions that return values, although I at the same time don't see why they couldn't, but just curious about your use case.
s

SrSouza

03/24/2022, 1:43 PM
Yes, I'm calling from inside a Compostable
z

Zach Klippenstein (he/him) [MOD]

03/24/2022, 3:01 PM
I'm guessing this isn't possible because Kotlin has very strict requirements for how the property delegate functions look. Composable functions have some extra parameters added to them by the compiler, so when it does that for these functions they no longer match the signature required for property delegate accessors.
🥲 1
The compose compiler should probably just complain upfront if you try doing this since that error message is a little opaque. Mind filing a bug?
6 Views