diff --git a/src/Chain.jl b/src/Chain.jl index 5972a50..f2f365b 100644 --- a/src/Chain.jl +++ b/src/Chain.jl @@ -78,7 +78,12 @@ function insert_first_arg(e::Expr, firstarg) error("You can only use the @. macro and automatic first argument insertion if what follows is of the form `[Module.SubModule.]func`") end - Expr(head, args[1], args[2], firstarg, args[3:end]...) + if length(args) >= 3 && args[3] isa Expr && args[3].head == :parameters + # macros can have keyword arguments after ; as well + Expr(head, args[1], args[2], args[3], firstarg, args[4:end]...) + else + Expr(head, args[1], args[2], firstarg, args[3:end]...) + end else insertionerror(e) diff --git a/test/runtests.jl b/test/runtests.jl index 7db3787..81edbad 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -380,4 +380,23 @@ end LocalModule.SubModule.@sin end @test y7 == LocalModule.SubModule.@sin(3) +end + +function kwfunc(y; x = 1) + y * x +end + +macro kwmac(exprs...) + :(kwfunc($(esc.(exprs)...))) +end + +@testset "keyword arguments" begin + + @test 6 == @chain 2 begin + kwfunc(; x = 3) + end + + @test 6 == @chain 2 begin + @kwmac(; x = 3) + end end \ No newline at end of file