Context: Newest IntelliJ, kotlin 2.0.
Problem: Kotlin selects correct overloaded method, but IntelliJ selects the wrong one and shows false positive on “Type mismatch, Required: T, found: Unit”.
Copy code
import java.util.function.Supplier
open class Bar {
fun <T> record(f: Supplier<T>): T {
println("$f is supplier")
return f.get()
}
fun record(f: Runnable): Unit {
println("$f is Runnable")
f.run()
}
}
class Foo : Bar() {
fun <T> foo(f: () -> T): T = try {
record(f)
} catch (e: Exception) {
throw e
}
}
Is this a known issue or should I create one in Youtrack?
s
Sam
07/16/2024, 2:03 PM
Do you have the K2 IDE mode switched on?
j
Jakub Gwóźdź
07/17/2024, 6:23 AM
No. Just enabled and the error is fixed indeed, just now I got the new one, so I need to decide which way do I prefer 🙂