Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support begin and end in gen_call_with_extracted_types users #45968

Merged
merged 1 commit into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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