I have a simple factory pattern where the implementation is determined through overload resolution. Problem is that the Kotlin compiler complains with "Overload resolution ambiguity.." for the inline lambda.
class Foo(){
companion object Factory {
fun create(x: Int, f: (Int) -> Double) = 2.0
fun create(x: Int, f: (Int) -> Int) = 1
}
}
fun main(args:Array<String>){
val a = Foo.create(1,::fromDouble) //OK
val b = Foo.create(1,::fromInt) //OK
val ambiguous = Foo.create(1){i -> 1.0} //Overload resolution ambiguity?
}
fun fromDouble(int:Int) = 1.0
fun fromInt(int:Int) = 1
How does the Kotlin compiler resolve overload resolution and why is the inline lambda considered to be ambiguous?
{ i: Int -> 1.0 } as (Int) -> Double
there's no ambiguity, but it says that cast is not needed. Also, if I extract the lambda toval l = { i: Int -> 1.0 }
and use it, again there's no ambiguity. Please search the bug tracker for this issue and if it's not there file a new one: youtrack.jetbrains.com/issues/KT – hotkey Mar 1 '16 at 20:37