https://kotlinlang.org logo
#coroutines
Title
# coroutines
t

Tolriq

07/22/2020, 7:41 AM
Just lost a couple of minutes for a strange issue with StateFlow. When using .collect {} it was automatically resolved to https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/common/src/flow/Flow.kt#L177 and did not propose the proper imports so obviously did not compile. Does anyone know why it resolved to that one without any related imports? (With 1.3.8) Manually adding the proper import fix the issue, but it's hard to figure out by default.
o

octylFractal

07/22/2020, 7:43 AM
because a FlowCollector is a Single-Abstract-Method interface
so
.collect {}
is technically valid for it
t

Tolriq

07/22/2020, 7:44 AM
Yes but why it's used without imports ? I would expect that it did not resolve and I had to import the proper one via alt+enter. Having default internal non usable thing used is weird.
o

octylFractal

07/22/2020, 7:45 AM
because it's a method on flow? it's not an extension, it's always there
it's like asking "how do you use
Any.toString()
without importing it"
t

Tolriq

07/22/2020, 7:49 AM
Well then having the extension name collision makes this strange to use, can't even use automatic IDE import resolution. Start by having an error then manual import does not sounds logical.
o

octylFractal

07/22/2020, 7:53 AM
yes, I think it is a really weird design choice -- I don't recall why it is this way, and I thought there was a related issue for de-prioritzing it in completions, but I can't find it now
t

Tolriq

07/22/2020, 8:30 AM
Oh nice it's fixed in 1.4 🙂 Thanks for the link.
5 Views