Skip to content

Commit

Permalink
Fix reflection macros for keyword calls
Browse files Browse the repository at this point in the history
Fix #18434
  • Loading branch information
yuyichao committed Sep 10, 2016
1 parent 600d363 commit 0e61f5e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
9 changes: 6 additions & 3 deletions base/interactiveutil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,12 @@ function gen_call_with_extracted_types(fcn, ex0)
if any(a->(Meta.isexpr(a, :kw) || Meta.isexpr(a, :parameters)), ex0.args)
# remove keyword args, but call the kwfunc
args = filter(a->!(Meta.isexpr(a, :kw) || Meta.isexpr(a, :parameters)), ex0.args)
return :($(fcn)(Core.kwfunc($(esc(args[1]))),
Tuple{Vector{Any}, typeof($(esc(args[1]))),
$(typesof)($(map(esc, args[2:end])...)).parameters...}))
return quote
local arg1 = $(esc(args[1]))
$(fcn)(Core.kwfunc(arg1),
Tuple{Vector{Any}, Core.Typeof(arg1),
$(typesof)($(map(esc, args[2:end])...)).parameters...})
end
elseif ex0.head == :call
return Expr(:call, fcn, esc(ex0.args[1]),
Expr(:call, typesof, map(esc, ex0.args[2:end])...))
Expand Down
15 changes: 15 additions & 0 deletions test/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -553,3 +553,18 @@ let
@test length(a) == 0
@test length(b) == 0
end

type A18434
end
(::Type{A18434})(x; y=1) = 1

global counter18434 = 0
function get_A18434()
global counter18434
counter18434 += 1
return A18434
end
@which get_A18434()(1; y=2)
@test counter18434 == 1
@which get_A18434()(1, y=2)
@test counter18434 == 2

0 comments on commit 0e61f5e

Please sign in to comment.