Skip to content

Commit

Permalink
Support do block works with @code_... macros
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Mar 28, 2020
1 parent 5808aea commit 26c5981
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions stdlib/InteractiveUtils/src/macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ function gen_call_with_extracted_types(__module__, fcn, ex0, kws=Expr[])
return Expr(:call, fcn, f,
Expr(:call, typesof, map(esc, ex0.args)...))
end
elseif ex0.head === :do && Meta.isexpr(get(ex0.args, 1, nothing), :call)
f = ex0.args[1].args[1]
args = [[ex0.args[2]]; ex0.args[1].args[2:end]]
return Expr(:call, fcn, esc(f), Expr(:call, typesof, map(esc, args)...),
kws...)
else
for (head, f) in (:ref => Base.getindex, :hcat => Base.hcat, :(.) => Base.getproperty, :vect => Base.vect, Symbol("'") => Base.adjoint, :typed_hcat => Base.typed_hcat, :string => string)
if ex0.head === head
Expand Down
3 changes: 3 additions & 0 deletions stdlib/InteractiveUtils/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ Base.getproperty(t::T1234321, ::Symbol) = "foo"
Base.setproperty!(t::T1234321, ::Symbol, ::Symbol) = "foo"
@test (@code_typed T1234321(1).f = :foo).second == String

# Make sure `do` block works with `@code_...` macros
@test (@code_typed map(1:1) do x; x; end).second == Vector{Int}

module ImportIntrinsics15819
# Make sure changing the lookup path of an intrinsic doesn't break
# the heuristic for type instability warning.
Expand Down

0 comments on commit 26c5981

Please sign in to comment.