Is this a bug or am I missing something? ```fun &l...
# announcements
d
Is this a bug or am I missing something?
Copy code
fun <T> List<T>.idk(): List<T> = TODO()
fun <T> List<T>?.idk(): List<T>? = TODO()

fun lol() {
	val real: List<String> = emptyList()
	val empty: List<String>? = emptyList()
	
	real.idk() // Resolves the first function.
	empty.idk() // Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type List<String>?
}
(Sorry about the names, they take up too much time to come up with) This only happens when the receiver is generic. The functions resolve as expected for
String
.
m
The
idk
functions both have same JVM signature, so the second one is ignored I think. If you remove the last line (
empty.idk()....
,) you should still get compilation error right?
m
Which Kotlin version are you using?
d
1.3.61
@Milan Hruban If the receiver is
String
, it compiles fine.
m
oh, it's because you are not on JVM, right?
d
Yes, sort of. It's common code.
m
Just as an experiment, could you try the same example in your environment with
-Xnew-inference
? Seems like a possible bug in type inference, maybe it's fixed in the new version.
d
Aiit
Ah I just remembered. New inference is enabled in the IDE by default.
I'll still try it anyway.
Yup,
Copy code
kotlinOptions {
    freeCompilerArgs = listOf("-Xnew-inference")
}
fixes it.
m
I guess the reason for the discrepancy is that IDEA is funky with its MPP support w.r.t. new inference, that's why it shows as invalid code in the IDE, but successfully compiles from the terminal
d
Hopefully it's fully enabled in 1.4 or smth.
m
As far as I know, that's the plan 😃
d
Haven't read the blog in a while. 😅