I feel silly having to ask this but… what’s going ...
# announcements
f
I feel silly having to ask this but… what’s going on here?
m
There are two functions called
flatMap
and the compiler doesn’t know which one to use. It will only know once you write code into
{ … }
so it knows what return type it’s dealing with.
✔️ 1
In
flatMap
you may either return a
List
or a
Sequence
.
f
oh in my dummy example I forgot to specify that
`
Copy code
foo.flatMap { it }
Screen Shot 2020-10-15 at 11.31.35.png
v
it
is red, why?
f
exactly, why
haha that’s my question 🙂
v
You show the error on
flatMap
, not the error on
it
What does IJ say?
f
unresolved ref
m
Works for me. I think you either have an old Kotlin version or are using the old type inference 🤔
f
I’m using
Copy code
val kotlinVersion = "1.3.72"
I could try updating
v
Btw. is that an artificial example or your real use-case?
If the latter, why not simply
foo.flatten()
?
m
Should work with 1.4.10. But you could also enable new type inference in 1.3.72 if you want to
v
The example should also work fine with 1.3.72, at least it does on play.kotl.in
s
so in 1.4.10 it’s on by default?
f
This is dummy example
s
(i mean the new type inference)
v
The new type inference is default on in 1.4, yes
But as I said, for me it works the same in 1.3.72
s
ah great
@Vampire for me too
m
Weird 😮
v
Does it also not compile or is only the IDE complaining?
m
Maybe a bug in New Inference in 1.3.72?
v
Why? It works in 1.3.72 with old inference on play.kotl.in
f
I ran a clean build and the issue persists. let me try compiling now
v
I don't think this has to do with new type inference
m
Why? It works in 1.3.72 with old inference on play.kotl.in
That’s why I suggest it may be an issue with 1.3.72's new inference
s
yeah it works for me
1.3.72
i just verified my version
m
With old or new inference?
s
looks like old inference, because I’m not aware I changed it
v
I doubt feresr accidentally switched to new inference, but who knows 😄
m
The IDE is automatically on new
compiler on old
s
ah ok
v
Is it? I thought I enabled it manually
Maybe I'm remembering wrongly
m
Not in IDE. It was enabled there to get early feedback on whether there are issues
s
Screen Shot 2020-10-15 at 16.41.50.png
m
But you could still compile if there are issues
v
Ah, yeah right, they enabled it by default in the IDE with 1.3.40
s
actually flatten(…) should be used I agree 😄
m
Works for me with 1.3.72 with OI and NI. Maybe an IDE bug then 🤷‍♂️
s
OI and NI?
f
still compiling, big project
v
old inference, new inference
s
well, you can set up a dummy project
and see if it works… well I shouldn’t say dummy
f
it compiles just fine!
v
And if you switch the inference algorithm in the IDE settings?
m
f
let met ry that
v
Ah, definitely looks related 😄
f
Looks very related, although the issue claims this works (with map)
Copy code
println(list.map { v -> v }) // Works
with flatmap doing this still gives the same error
Copy code
val foo = listOf(listOf(1, 2, 3), listOf(4, 5, 6))
        println(foo.flatMap { v -> v }) // Error
v
image.png
f
And if you switch the inference algorithm in the IDE settings?
not sure where to find this
v
https://blog.jetbrains.com/kotlin/2019/06/kotlin-1-3-40-released/ heading "Working on a New Type Inference Algorithm"
m
Search for the settings group “Kotlin Compiler”
f
Thank you! just enabled it
same thing
althoug… do I need to restar the IDE or rebuild the project?
for it to take effect
m
I have no idea 🙂
v
I don't remember
Try with something that is documented in the release notes as working with the new inference but not with the old
This way you know which algo is used
Or just update your Kotlin plugin in the IDE. Doesn't mean you have to update your project, especially as compiling worked fine.
f
Wait I was wrong before. I’m actually using
Copy code
kotlin_version = "1.4.10"
sorry for the confusion I checked the wrong thing before
I’ll try updating the kotlin plugin
s
😄
f
it’s working now! my bad, I was using an old plugin version
🎉 3
thank you all for the help 🙂
i
To summarize,
flatMap
in question works in 1.3.72 both with the old and the new inference because there's only one overload of it for the particular receiver. Then,
flatMap
works in 1.4.0 because the compiler knows how to select from its two overloads, one of which was introduced in 1.4.0. What doesn't work is using the standard library 1.4.0 with the compiler/IDE plugin 1.3.72.
v
Ah, that makes sense, thanks for clarification
Would
flatMap
with standard library 1.4.0, IDE plugin 1.3.72 and new inference activated have worked?
i
No, the overload resolution by lambda return type was implemented only in 1.4.0
✔️ 1