-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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 do
block with @code_...
macros
#35283
Conversation
do
block works with @code_...
macrosdo
block with @code_...
macros
Nice addition! But it seems to me you are not taking into account the possible presence of keyword arguments: julia> open("VERSION"; read=true) do f; f end
IOStream(<file VERSION>)
julia> @code_typed open("VERSION"; read=true) do f; f end
ERROR: syntax: invalid syntax ; read = true
Stacktrace:
[1] top-level scope at REPL[15]:1 |
I think one option is to lower the do-block by hand near the entry point of the function, so modifying the diff --git a/stdlib/InteractiveUtils/src/macros.jl b/stdlib/InteractiveUtils/src/macros.jl
index e6dd8cb7d1..91b6521bfa 100644
--- a/stdlib/InteractiveUtils/src/macros.jl
+++ b/stdlib/InteractiveUtils/src/macros.jl
@@ -8,6 +8,14 @@ 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)
+ insert!(ex0.args[1].args, (isnothing(i) ? 2 : i+1), ex0.args[2])
+ ex0 = ex0.args[1]
+ end
if any(a->(Meta.isexpr(a, :kw) || Meta.isexpr(a, :parameters)), ex0.args)
return quote
local arg1 = $(esc(ex0.args[1])) Another option would probably be to check for keywords at the point where you originally added the do-block handling. |
This reverts commit 26c5981.
Co-authored-by: Liozou <Liozou@users.noreply.github.com>
@Liozou Thanks a lot for looking into this! I switched to your patch. |
Glad I could help! :) |
This PR makes invocations like
@code_typed map(1:1) do x; x; end
work.