diff --git a/stdlib/InteractiveUtils/src/macros.jl b/stdlib/InteractiveUtils/src/macros.jl index 7ef15bcd5fdff..1aa207d77a42b 100644 --- a/stdlib/InteractiveUtils/src/macros.jl +++ b/stdlib/InteractiveUtils/src/macros.jl @@ -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)) @@ -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 diff --git a/stdlib/InteractiveUtils/test/runtests.jl b/stdlib/InteractiveUtils/test/runtests.jl index 4d7fad2b387cc..685299143acc0 100644 --- a/stdlib/InteractiveUtils/test/runtests.jl +++ b/stdlib/InteractiveUtils/test/runtests.jl @@ -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