diff --git a/base/expr.jl b/base/expr.jl index 2fb3559d1b9f6..7719eff3b334b 100644 --- a/base/expr.jl +++ b/base/expr.jl @@ -574,6 +574,7 @@ macro generated(f) if isa(f, Expr) && (f.head === :function || is_short_function_def(f)) body = f.args[2] lno = body.args[1] + tmp = gensym("tmp") return Expr(:escape, Expr(f.head, f.args[1], Expr(:block, @@ -581,8 +582,8 @@ macro generated(f) Expr(:if, Expr(:generated), # https://github.com/JuliaLang/julia/issues/25678 Expr(:block, - :(local tmp = $body), - :(if tmp isa Core.CodeInfo; return tmp; else tmp; end)), + :(local $tmp = $body), + :(if $tmp isa $(GlobalRef(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 354f014733c7e..0bfafa1355c19 100644 --- a/test/syntax.jl +++ b/test/syntax.jl @@ -2981,6 +2981,21 @@ end @generated g25678(x) = return :x @test g25678(7) === 7 +# issue 25678: module of name `Core` +# https://github.com/JuliaLang/julia/pull/40778/files#r784416018 +@test @eval Module() begin + Core = 1 + @generated f() = 1 + f() == 1 +end + +# issue 25678: argument of name `tmp` +# https://github.com/JuliaLang/julia/pull/43823#discussion_r785365312 +@test @eval Module() begin + @generated f(tmp) = tmp + f(1) === Int +end + # issue #19012 @test Meta.parse("\U2200", raise=false) == Symbol("∀") @test Meta.parse("\U2203", raise=false) == Symbol("∃")