Skip to content

Commit

Permalink
fix #25678: return matters for generated functions (#40778)
Browse files Browse the repository at this point in the history
Just explicitely check for `CodeInfo` objects and use an explicit
`return` in this case inside the `@generated` macro.

Co-authored-by: Jeff Bezanson <[email protected]>
  • Loading branch information
simeonschaub and JeffBezanson authored Aug 24, 2021
1 parent 3d058b2 commit 92c84bf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion base/expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,10 @@ macro generated(f)
Expr(:block,
lno,
Expr(:if, Expr(:generated),
body,
# https://github.com/JuliaLang/julia/issues/25678
Expr(:block,
:(local tmp = $body),
:(if tmp isa Core.CodeInfo; return tmp; else tmp; end)),
Expr(:block,
Expr(:meta, :generated_only),
Expr(:return, nothing))))))
Expand Down
7 changes: 7 additions & 0 deletions test/syntax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2959,3 +2959,10 @@ end
ex.args = fill!(Vector{Any}(undef, 600000), 1)
@test_throws ErrorException("syntax: expression too large") eval(ex)
end

# issue 25678
@generated f25678(x::T) where {T} = code_lowered(sin, Tuple{x})[]
@test f25678(pi/6) === sin(pi/6)

@generated g25678(x) = return :x
@test g25678(7) === 7

0 comments on commit 92c84bf

Please sign in to comment.