diff --git a/base/expr.jl b/base/expr.jl index 9df363714679e..af4f5879c32e4 100644 --- a/base/expr.jl +++ b/base/expr.jl @@ -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)))))) diff --git a/test/syntax.jl b/test/syntax.jl index 95242b44b4871..9b31c0b874fbd 100644 --- a/test/syntax.jl +++ b/test/syntax.jl @@ -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