Why does this give a `ClassCastException` (for the `first` of the `Pair`): ```internal fun Pair<@...
m
Why does this give a
ClassCastException
(for the
first
of the
Pair
):
Copy code
internal fun Pair<@Composable () -> String, (() -> Unit)?>.toButton(): @Composable () -> Unit = {
    var (label, onClick) = this@toButton // same runtime exception if use `this.first` instead
    ...
}
s
Can you paste the exception? Also looks like a bug, feel free to file an issue on tracker.
m
I believe I’ve discovered the issue. I have a property declared like:
var positiveButton: (Pair<@Composable () -> String, T>)? = null
Usually, I assign it like:
positiveButton = @Composable { stringResource(id = labelResId) } to value
But sometimes like:
positiveButton = { label } to value
and that is what is causing the crash. Instead, I just need to assign like:
positiveButton = @Composable { label } to value
Surely this is a bug? Either the compiler should pick it up, or the runtime should allow it.
s
Yes, that's definitely a bug
m
Can you reproduce it?
s
Didn't try to yet, but feel free to file a bug on the tracker :)
s
Just to leave a note here, I investigated this issue and seems like it is a limitation of compiler plugin in K1. It doesn't propagate the type of the receiver to the compiler plugin and in this case
{ label }
is a receiver for the
to
call. From what I see, it should be properly fixed in K2 inference, but cannot predict if that's the case atm.