Skip to content

Commit 26c5981

Browse files
committed
Support do block works with @code_... macros
1 parent 5808aea commit 26c5981

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

stdlib/InteractiveUtils/src/macros.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ function gen_call_with_extracted_types(__module__, fcn, ex0, kws=Expr[])
5151
return Expr(:call, fcn, f,
5252
Expr(:call, typesof, map(esc, ex0.args)...))
5353
end
54+
elseif ex0.head === :do && Meta.isexpr(get(ex0.args, 1, nothing), :call)
55+
f = ex0.args[1].args[1]
56+
args = [[ex0.args[2]]; ex0.args[1].args[2:end]]
57+
return Expr(:call, fcn, esc(f), Expr(:call, typesof, map(esc, args)...),
58+
kws...)
5459
else
5560
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)
5661
if ex0.head === head

stdlib/InteractiveUtils/test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ Base.getproperty(t::T1234321, ::Symbol) = "foo"
9090
Base.setproperty!(t::T1234321, ::Symbol, ::Symbol) = "foo"
9191
@test (@code_typed T1234321(1).f = :foo).second == String
9292

93+
# Make sure `do` block works with `@code_...` macros
94+
@test (@code_typed map(1:1) do x; x; end).second == Vector{Int}
95+
9396
module ImportIntrinsics15819
9497
# Make sure changing the lookup path of an intrinsic doesn't break
9598
# the heuristic for type instability warning.

0 commit comments

Comments
 (0)