diff --git a/stdlib/InteractiveUtils/src/macros.jl b/stdlib/InteractiveUtils/src/macros.jl index e6dd8cb7d17dac..d3695cc437834e 100644 --- a/stdlib/InteractiveUtils/src/macros.jl +++ b/stdlib/InteractiveUtils/src/macros.jl @@ -8,6 +8,15 @@ separate_kwargs(args...; kwargs...) = (args, kwargs.data) function gen_call_with_extracted_types(__module__, fcn, ex0, kws=Expr[]) if isa(ex0, Expr) + if ex0.head === :do && Meta.isexpr(get(ex0.args, 1, nothing), :call) + if length(ex0.args) != 2 + return Expr(:call, :error, "ill-formed do call") + end + i = findlast(a->(Meta.isexpr(a, :kw) || Meta.isexpr(a, :parameters)), ex0.args[1].args) + args = copy(ex0.args[1].args) + insert!(args, (isnothing(i) ? 2 : i+1), ex0.args[2]) + ex0 = Expr(:call, args...) + end if any(a->(Meta.isexpr(a, :kw) || Meta.isexpr(a, :parameters)), ex0.args) return quote local arg1 = $(esc(ex0.args[1])) diff --git a/stdlib/InteractiveUtils/test/runtests.jl b/stdlib/InteractiveUtils/test/runtests.jl index b5d2abc39a1b72..808aa6de85981e 100644 --- a/stdlib/InteractiveUtils/test/runtests.jl +++ b/stdlib/InteractiveUtils/test/runtests.jl @@ -90,6 +90,10 @@ 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} +@test (@code_typed open(`cat`; read=true) do _; 1; end).second == Int + module ImportIntrinsics15819 # Make sure changing the lookup path of an intrinsic doesn't break # the heuristic for type instability warning.