What am I missing here? This should compile, right...
# coroutines
u
What am I missing here? This should compile, right?
Copy code
GlobalScope.launch {
            flowOf(1,2,3,4,5)
                .delayEach(500)
                .map { it * it }
                .collect { println(it) } // Type mismatch: inferred type is () -> ??? but FlowCollector<Int> was expected
        }
t
for me it does compile...
s
This may have improved with the new type inference of Kotlin v1.3.40. Malte may have that newest version, while you may have 1.3.31 or older...
t
even with 1.3.31 is seems to work well: https://pl.kotl.in/RYtHet74G
v
Check your imports for kotlinx.coroutines.flow.collect
u
I tested this with both 1.3.40 and 1.3.31
I'll try the good ol' invalidate caches & restart, I guess
Well I'll be damned, I actually had to manually import the
collect
extension, because apparently without the import it references
Flow::collect
, resulting in the compile error. That's... unfortunate. Thanks @Vlad
e
Does it reproduce?
u
In my project it does. I'll try to reproduce it in a fresh one.
It does actually. I mean, it can be easily remedied by pressing CTRL+Space on the
collect
method and selecting the extension function instead. It's just that the error was a bit misleading in the beginning, because a different
collect
method is being referenced by default (the one with
@InternalCoroutinesApi
in
Flow
).