Skip to content

Commit

Permalink
Support begin and end in gen_call_with_extracted_types users (JuliaLa…
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Atol authored and pcjentsch committed Aug 18, 2022
1 parent 0c26dc5 commit c669dc1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion stdlib/InteractiveUtils/src/macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# macro wrappers for various reflection functions

import Base: typesof, insert!
import Base: typesof, insert!, replace_ref_begin_end!

separate_kwargs(args...; kwargs...) = (args, values(kwargs))

Expand Down Expand Up @@ -32,6 +32,9 @@ function recursive_dotcalls!(ex, args, i=1)
end

function gen_call_with_extracted_types(__module__, fcn, ex0, kws=Expr[])
if Meta.isexpr(ex0, :ref)
ex0 = replace_ref_begin_end!(ex0)
end
if isa(ex0, Expr)
if ex0.head === :do && Meta.isexpr(get(ex0.args, 1, nothing), :call)
if length(ex0.args) != 2
Expand Down
11 changes: 11 additions & 0 deletions stdlib/InteractiveUtils/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -706,3 +706,14 @@ end
end
end
end

@testset "begin/end in gen_call_with_extracted_types users" begin
mktemp() do f, io
redirect_stdout(io) do
a = [1,2]
@test (@code_typed a[1:end]).second == Vector{Int}
@test (@code_llvm a[begin:2]) === nothing
@test (@code_native a[begin:end]) === nothing
end
end
end

0 comments on commit c669dc1

Please sign in to comment.