Skip to content

Commit acc7401

Browse files
committed
fixes #8
1 parent 0ecb56a commit acc7401

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/function.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ 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]
105+
def[:kwargs] = arg isa Symbol ? [arg] : [:($(Expr(:kw, arg.args...)))]
106106
else
107107
return invalid_def("an invalid block expression as arguments")
108108
end

test/function.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,28 @@ function_form(short::Bool) = string(short ? "short" : "long", "-form")
545545
@test strip_lineno!(c_expr) == strip_lineno!(expr)
546546
end
547547

548+
@testset "(x; y = 0)" begin
549+
f, expr = if short
550+
@audit (x; y = 0) -> (x, y)
551+
else
552+
@audit function (x; y = 0); (x, y) end
553+
end
554+
@test length(methods(f)) == 1
555+
@test f(0) == (0, 0)
556+
@test f(0, y=1) == (0, 1)
557+
558+
# Note: the semi-colon is missing from the expression
559+
d = splitdef(expr)
560+
@test keys(d) == Set([:head, :args, :kwargs, :body])
561+
@test d[:args] == [:x]
562+
@test d[:kwargs] == [Expr(:kw, :y, 0)]
563+
564+
c_expr = combinedef(d)
565+
expr = Expr(:->, Expr(:tuple, Expr(:parameters, Expr(:kw, :y, 0)), :x), Expr(:block, :((x, y))))
566+
expr.head = short ? :-> : :function
567+
@test strip_lineno!(c_expr) == strip_lineno!(expr)
568+
end
569+
548570
@testset "Expr(:block, :x, :y)" begin
549571
expr = Expr(:->, Expr(:block, :x, :y), Expr(:block, :((x, y))))
550572
expr.head = short ? :-> : :function

0 commit comments

Comments
 (0)