"@inferred requires a call expression" for do notation
Lambda functions work fine, while the same do-block throws an error:
julia> using Test
julia> @inferred map(x->x, [1,2])
2-element Vector{Int64}:
1
2
julia> @inferred map([1,2]) do x
x
end
ERROR: LoadError: @inferred requires a call expression
gen_call_with_extracted_types already supports the required rewrite, just needs a few small tweaks in the macro itself.
@aplavin Hi! 👋 I'd like to work on this issue.
The behavior here appears to come from the fact that @inferred only accepts a call expression in its macro expansion, and the do-block form (map([1,2]) do x ... end) lowers into a different AST shape than a standard call. As a result, the macro rejects the input before inference is even attempted.
I’m interested in implementing a fix so that @inferred supports do-block syntax in the same way it supports anonymous function calls. My plan is to update the macro to normalize or expand do-block forms into an equivalent call expression before the argument checks, allowing the expected inference test to run.
Before I begin preparing a PR, are there any prior discussions, preferred patterns for macro normalization, or compatibility concerns I should be aware of? If the approach sounds reasonable, please assign the issue to me—I’d be happy to take it on.
Thanks!
@gsiddharthrao, Note that while LLMs and AI can be useful help when coding, in this repo, it is quite important to state when such a tool is extensively used, even if it is for writing comments.
Also, we don't, in general, assign issues to people to avoid cookie licking. You can still make a PR without anything being assigned to you.
Note https://github.com/JuliaLang/julia/pull/59463 seems to be an existing PR along this approach.
Hey !! I would like to fix this issue
could you please redirect me to the source code from where it belongs
Hi! I tried reproducing this and it seems related to macro expansion order. @inferred expects a call expression, but do-block syntax is lowered after macros run, so the macro sees a non-call expression and throws an error. Wrapping the expression in parentheses works: julia @inferred (map([1,2]) do x x end)
Thanks for the clarification — that makes sense.
If this is considered expected behavior, I’d be happy to work on a small follow-up: either a documentation note mentioning the need for parentheses with do-blocks, or an improved error message pointing this out.
Please let me know what would be preferred.
are these accounts all from the same entity ...?
are these accounts all from the same entity ...?
no