Expronicon.jl icon indicating copy to clipboard operation
Expronicon.jl copied to clipboard

function keyword arguments default values are not generated

Open domluna opened this issue 3 years ago • 2 comments

julia> JLFunction(;name="foo", kwargs=[JLKwField(;name=:arg1, default=10)])^C

julia> kw = JLKwField(;name=:arg1, default=10, type=:Int)
arg1::Int

julia> f = JLFunction(;name="foo", kwargs=[kw])
function "foo"(; arg1::Int)
end

julia> codegen_ast(a)
:(arg1::Int)

julia> codegen_ast(f)
:(function ("foo")(; arg1::Int)
  end)

This should be arg1::Int=10. Changing 10 to a Symbol has the same result.

domluna avatar Sep 04 '21 18:09 domluna

https://github.com/Roger-luo/Expronicon.jl/blob/master/src/codegen.jl#L440-L446

JLKwField needs it's own codegen func, I can make a PR

domluna avatar Sep 04 '21 18:09 domluna

ah thanks! good catch!

the JLKwField was intended to use for JLKwStruct at the beginning, so what actually should be in JLFunction is Expr(:kw, name, default), I should have used JLKwField in JLFunction too, but I was too lazy :P

JLKwField needs it's own codegen func, I can make a PR

Please feel free to open one! I can also help on it

Roger-luo avatar Sep 04 '21 19:09 Roger-luo