Skip to content

Commit b0ab5d1

Browse files
committed
tighter condition
1 parent acc7401 commit b0ab5d1

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/function.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,11 @@ function splitdef(ex::Expr; throw::Bool=true)
102102
if !haskey(def, :args)
103103
def[:args] = [arg]
104104
elseif !haskey(def, :kwargs)
105-
def[:kwargs] = arg isa Symbol ? [arg] : [:($(Expr(:kw, arg.args...)))]
105+
if arg isa Expr && arg.head == :(=)
106+
def[:kwargs] = [:($(Expr(:kw, arg.args...)))]
107+
else
108+
def[:kwargs] = [arg]
109+
end
106110
else
107111
return invalid_def("an invalid block expression as arguments")
108112
end

test/function.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,29 @@ function_form(short::Bool) = string(short ? "short" : "long", "-form")
567567
@test strip_lineno!(c_expr) == strip_lineno!(expr)
568568
end
569569

570+
@testset "(x; y = 0, _...)" begin
571+
f, expr = if short
572+
@audit (x; y = 0, _...) -> (x, y)
573+
else
574+
@audit function (x; y = 0, _...); (x, y) end
575+
end
576+
@test length(methods(f)) == 1
577+
@test f(0) == (0, 0)
578+
@test f(0, y=1) == (0, 1)
579+
@test f(0, y=1, z=2) == (0, 1)
580+
581+
# Note: the semi-colon is missing from the expression
582+
d = splitdef(expr)
583+
@test keys(d) == Set([:head, :args, :kwargs, :body])
584+
@test d[:args] == [:x]
585+
@test d[:kwargs] == [Expr(:kw, :y, 0), :(_...)]
586+
587+
c_expr = combinedef(d)
588+
expr = Expr(:->, Expr(:tuple, Expr(:parameters, Expr(:kw, :y, 0), :(_...)), :x), Expr(:block, :((x, y))))
589+
expr.head = short ? :-> : :function
590+
@test strip_lineno!(c_expr) == strip_lineno!(expr)
591+
end
592+
570593
@testset "Expr(:block, :x, :y)" begin
571594
expr = Expr(:->, Expr(:block, :x, :y), Expr(:block, :((x, y))))
572595
expr.head = short ? :-> : :function

0 commit comments

Comments
 (0)