Skip to content

Commit 8536522

Browse files
Use GlobalRef of Core.CodeInfo in @generated (#43823)
Co-authored-by: Simeon Schaub <schaub@mit.edu>
1 parent b65c19a commit 8536522

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

base/expr.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,15 +574,16 @@ macro generated(f)
574574
if isa(f, Expr) && (f.head === :function || is_short_function_def(f))
575575
body = f.args[2]
576576
lno = body.args[1]
577+
tmp = gensym("tmp")
577578
return Expr(:escape,
578579
Expr(f.head, f.args[1],
579580
Expr(:block,
580581
lno,
581582
Expr(:if, Expr(:generated),
582583
# https://github.com/JuliaLang/julia/issues/25678
583584
Expr(:block,
584-
:(local tmp = $body),
585-
:(if tmp isa Core.CodeInfo; return tmp; else tmp; end)),
585+
:(local $tmp = $body),
586+
:(if $tmp isa $(GlobalRef(Core, :CodeInfo)); return $tmp; else $tmp; end)),
586587
Expr(:block,
587588
Expr(:meta, :generated_only),
588589
Expr(:return, nothing))))))

test/syntax.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2981,6 +2981,21 @@ end
29812981
@generated g25678(x) = return :x
29822982
@test g25678(7) === 7
29832983

2984+
# issue 25678: module of name `Core`
2985+
# https://github.com/JuliaLang/julia/pull/40778/files#r784416018
2986+
@test @eval Module() begin
2987+
Core = 1
2988+
@generated f() = 1
2989+
f() == 1
2990+
end
2991+
2992+
# issue 25678: argument of name `tmp`
2993+
# https://github.com/JuliaLang/julia/pull/43823#discussion_r785365312
2994+
@test @eval Module() begin
2995+
@generated f(tmp) = tmp
2996+
f(1) === Int
2997+
end
2998+
29842999
# issue #19012
29853000
@test Meta.parse("\U2200", raise=false) == Symbol("")
29863001
@test Meta.parse("\U2203", raise=false) == Symbol("")

0 commit comments

Comments
 (0)