Skip to content

Commit 224caa0

Browse files
committed
Fix handling of kwargs in atsign-interpret (fixes #113)
1 parent d5fbe82 commit 224caa0

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/JuliaInterpreter.jl

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,22 +1038,18 @@ end
10381038

10391039
lower(mod, arg) = false ? expand(arg) : Meta.lower(mod, arg)
10401040

1041-
# This is a version of gen_call_with_extracted_types, except that is passes back the call expression
1042-
# for further processing.
1041+
separate_kwargs(args...; kwargs...) = (args, kwargs.data)
1042+
1043+
# This is a version of InteractiveUtils.gen_call_with_extracted_types, except that is passes back the
1044+
# call expression for further processing.
10431045
function extract_args(__module__, ex0)
10441046
if isa(ex0, Expr)
1045-
kws = collect(filter(x->isexpr(x,:kw),ex0.args))
1046-
if !isempty(kws)
1047-
names = []
1048-
values = Tuple(map(x-> begin
1049-
push!(names,x.args[1])
1050-
x.args[2]
1051-
end,kws))
1052-
names = Tuple(names)
1053-
return Expr(:tuple,:(Core.kwfunc($(ex0.args[1]))),
1054-
Expr(:call, NamedTuple{names,typeof(values)}, values),
1055-
map(x->isexpr(x, :parameters) ? QuoteNode(x) : x,
1056-
filter(x->!isexpr(x, :kw),ex0.args))...)
1047+
if any(a->(Meta.isexpr(a, :kw) || Meta.isexpr(a, :parameters)), ex0.args)
1048+
return quote
1049+
local arg1 = $(ex0.args[1])
1050+
local args, kwargs = $separate_kwargs($(ex0.args[2:end]...))
1051+
tuple(Core.kwfunc(arg1), kwargs, arg1, args...)
1052+
end
10571053
elseif ex0.head == :.
10581054
return Expr(:tuple, :getproperty, ex0.args...)
10591055
elseif ex0.head == :(<:)

test/interpret.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,10 @@ end
314314
@interpret f106c()
315315
@interpret f106d()
316316

317+
# issue #113
318+
f113(;x) = x
319+
@test @interpret(f113(;x=[1,2,3])) == f113(;x=[1,2,3])
320+
317321
# Some expression can appear nontrivial but lower to nothing
318322
@test isa(JuliaInterpreter.prepare_thunk(Main, :(@static if ccall(:jl_get_UNAME, Any, ()) == :NoOS 1+1 end)), Nothing)
319323
@test isa(JuliaInterpreter.prepare_thunk(Main, :(Base.BaseDocs.@kw_str "using")), Nothing)

0 commit comments

Comments
 (0)