Hi! Can someone explain why julia compiler allows the following function declaration:
fun(arg::String=nothing) = arg
Which is quite confusing especially considering that julia itself claims that there are two methods for the function fun
:
julia> methods(fun)
# 2 methods for generic function "fun":
[1] fun() in Main at REPL[10]:1
[2] fun(arg::String) in Main at REPL[10]:1
However, if one attempts to call fun()
there is an exception
julia> fun()
ERROR: MethodError: no method matching fun(::Nothing)
Closest candidates are:
fun() at REPL[10]:1
fun(::String) at REPL[10]:1
Stacktrace:
[1] fun()
@ Main ./REPL[10]:1
[2] top-level scope
@ REPL[11]:1