Peter Quade
11/16/2017, 2:14 PMpopcorn:withSalt:
and popcorn:withSugar:
distinguished on the kotlin side?Peter Quade
11/16/2017, 2:15 PMpopcorn(foo, withSalt=1)
and popcorn(foo, withSugar=2)
on the kotlin side. But what does popcorn(foo, 1)
mean then?Peter Quade
11/16/2017, 2:18 PMfun foo(a: Int, b:Int) : Int {
return a + b
}
fun foo(a: Int, c:Int) :Int {
return a - c
}
fun main(args : Array<String>) {
println(foo(1,2))
println(foo(a=1, b=2))
println(foo(a=1, c=2))
}
So it seems kotlin can distinguish methods (functions) based on the parameter names (the REPL can). But the compiler does not like it, because it's dangerous and ambigous.
(kotlin-native is still building on my machine so I have not tried this yet with kotlin-native. I just looked at the interop code and the samples, and was curious how this is supposed to work)svyatoslav.scherbina
11/16/2017, 2:37 PMIt seems they would be callable asYes, exactly.andpopcorn(foo, withSalt=1)
on the kotlin side.popcorn(foo, withSugar=2)
But what doesmean then?popcorn(foo, 1)
popcorn(foo, 1)
means nothing, because it is ambiguous. The compiler doesn’t accept this.
kotlin-native is still building on my machinePlease note that we have’ve just released Kotlin/Native 0.4, mostly corresponding to current state of
master
. So you probably can just download the built release.Peter Quade
11/16/2017, 3:12 PMpopcorn(foo, 1)
work, if there is only one matching objc selector (just popcorn:withSalt:
not ...withSugar:
existing)?
(I’ve seen lot’s of objc interop approaches to different languages and I’m always curious how the fundamental question of selector->function_call is answered 😉
And thank you for mentioning the binaries. I was not aware of them.orangy
But the compiler does not like it, because it’s dangerous and ambigous.it’s not the Kotlin compiler, it’s JVM that doesn’t allow this.
olonho
11/16/2017, 7:08 PM@file:Suppress("CONFLICTING_OVERLOADS")
fun foo(a: Int, b:Int) : Int {
return a + b
}
fun foo(a: Int, c:Int) :Int {
return a - c
}
fun main(args: Array<String>) {
println(foo(a=2, c=1))
println(foo(a=2, b=1))
// Doesn't compile.
// println(foo(a=2, 1))
}
Peter Quade
11/17/2017, 12:44 PM