julia
julia copied to clipboard
Underscore not allowed with optional parameters
julia> f(_, a) = 10
f (generic function with 1 method)
julia> f(_, a=1) = 10
ERROR: syntax: all-underscore identifier used as rvalue around REPL[0]:1
The second form seems legitimate, no? The same issue arises with keyword arguments (f(_; x=1) = ...)
It does seem like a good way to indicate that you don't care about an argument, similar to ::Any but shorter.
Ah, naturally this is due to lowering converting the definition to
f(_) = f(_, 1)
f(_, a) = 10
Could be nice to lower _ as a function argument to @nospecialize(_)
how does the lowering for keyword arguments look like? is it the same reason there?
LanguageServer.jl now offers a quickfix code action for replacing unused argument with _ (https://github.com/julia-vscode/LanguageServer.jl/pull/1072), but then you run into this issue pretty often.