https://kotlinlang.org logo
#serialization
Title
# serialization
l

Lukasz Kalnik

08/16/2022, 11:10 AM
Ah ok, I see, this is not a member function but an extension function and has to be manually imported:
Copy code
import kotlinx.serialization.decodeFromString
🧵 1
l

Lukáš Kúšik

08/16/2022, 11:13 AM
you can usually press enter on the correct autocomplete entry and it will do the correct import, although it is bad that the IDE behaves like this in the first place
l

Lukasz Kalnik

08/16/2022, 11:15 AM
The autocomplete didn't suggest the extension function. I suppose that's because the member function is obscuring the extension function.
They both have the same name.
IDE doesn't give suggestions for alternative extension functions if it sees only the signature mismatch
You're right, maybe I just didn't notice it
But after you've chosen the wrong one (like me), IDE doesn't give any hint that the problem might be fixed with an import. But I guess this is too much to expect right now.
Thanks for the hint!
l

Lukáš Kúšik

08/16/2022, 11:21 AM
if you somehow break the flow, the IDE gets stuck on the member function and does not offer you to import the extension function - like in your case. I consider this a bug and I think there are already issues for this opened. What I usually do is that I start retyping the function name and select the correct suggestion, it will then snap into the right state 🙂
l

Lukasz Kalnik

08/16/2022, 11:22 AM
That's a good tip. What I usually do, I go into the source code of the class and search for the missing overload. Which didn't help here, as the extension
decodeFromString()
is in a different file than the member function 🙂
And anyway from the Compose world I know the problems e.g. when using
Copy code
var expanded by remember { mutableStateOf(false) }
where you just get error messages that `getValue()`/`setValue()` is missing and the only way to fix it is to add appropriate imports manually. So it's easy to get confused between all these IDE/Kotlin compiler inconsistencies.
l

Lukáš Kúšik

08/16/2022, 11:29 AM
I often stumble upon this issue with LazyLists using Paging 😄
Copy code
LazyListScope.items(items: LazyPagingItems<T>)
l

Lukasz Kalnik

08/16/2022, 11:29 AM
Ah, good to know, haven't yet used LazyList.
3 Views