Skip to content

Commit b3e148c

Browse files
committed
fix: issue in generating :kw for anonymous functions
1 parent 0786002 commit b3e148c

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/utils.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,12 @@ function longdef1(ex)
271271
kw_args = []
272272
for a in arg.args
273273
if !(a isa LineNumberNode)
274-
if isexpr(a, :...) || isexpr(a, :(=)) || isexpr(a, :kw)
274+
if isexpr(a, :...)
275+
push!(kw_args, a)
276+
elseif isexpr(a, :(=))
277+
# Transform = to :kw for keyword arguments
278+
push!(kw_args, Expr(:kw, a.args[1], a.args[2]))
279+
elseif isexpr(a, :kw)
275280
push!(kw_args, a)
276281
else
277282
push!(pos_args, a)

test/split.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ let
115115
# Both splatted positional and keyword arguments
116116
@test (@splitcombine (a::Int, args::Int...; kws...) -> a + sum(args) + sum(values(kws)))(1, 2, 3; b=4, c=5) == 15
117117
@test (@splitcombine (a, ::Int...; b, kws...) -> a + sum(values(kws)))(1, 2, 3; b=4, c=5) == 1 + 5
118+
119+
# Issue with longdef
120+
ex = longdef(:((a::Int; b=2) -> a + b))
121+
any_kw(ex) = ex isa Expr ? (any_kw(ex.head) || any(any_kw, ex.args)) : ex == :kw
122+
@test any_kw(ex)
123+
## ^Ensure we get a :kw expression in the output AST
124+
@test eval(ex) isa Function
125+
## Shouldn't have issues evaluating
118126
end
119127

120128
@testset "combinestructdef, splitstructdef" begin

0 commit comments

Comments
 (0)