Function overload with default args ambiguity with no-arg function

If I declare two functions with the same signatures (with respect to default arguments), the no arg function is always called and the rest is not called unless you pass the args (or at least one of the args).
For example I have these two functions in same scope:

fun foo(): Int {
    return -1

fun foo(arg1: Boolean = false): Double {
    return 0.0

Now if I call foo(), it will return -1 always (unless I pass the false, of course) and even no error/warning is reported.
Is that the intended behavior? I think it would be better if the compiler not allow to declare such ambiguous functions at all or at least report a warning in declaration/use site.


To be honest Iā€™m also surprised this compiles :confused:

1 Like