Skip to content

Commit f5d02a1

Browse files
devmotionsimeonschaub
authored andcommitted
Use GlobalRef of Core.CodeInfo in @generated (#43823)
Co-authored-by: Simeon Schaub <schaub@mit.edu> (cherry picked from commit 8536522)
1 parent 9e5ad01 commit f5d02a1

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
@@ -441,15 +441,16 @@ macro generated(f)
441441
if isa(f, Expr) && (f.head === :function || is_short_function_def(f))
442442
body = f.args[2]
443443
lno = body.args[1]
444+
tmp = gensym("tmp")
444445
return Expr(:escape,
445446
Expr(f.head, f.args[1],
446447
Expr(:block,
447448
lno,
448449
Expr(:if, Expr(:generated),
449450
# https://github.com/JuliaLang/julia/issues/25678
450451
Expr(:block,
451-
:(local tmp = $body),
452-
:(if tmp isa Core.CodeInfo; return tmp; else tmp; end)),
452+
:(local $tmp = $body),
453+
:(if $tmp isa $(GlobalRef(Core, :CodeInfo)); return $tmp; else $tmp; end)),
453454
Expr(:block,
454455
Expr(:meta, :generated_only),
455456
Expr(:return, nothing))))))

test/syntax.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2954,6 +2954,21 @@ end
29542954
@test f() == (2, 3)
29552955
end
29562956

2957+
# issue 25678: module of name `Core`
2958+
# https://github.com/JuliaLang/julia/pull/40778/files#r784416018
2959+
@test @eval Module() begin
2960+
Core = 1
2961+
@generated f() = 1
2962+
f() == 1
2963+
end
2964+
2965+
# issue 25678: argument of name `tmp`
2966+
# https://github.com/JuliaLang/julia/pull/43823#discussion_r785365312
2967+
@test @eval Module() begin
2968+
@generated f(tmp) = tmp
2969+
f(1) === Int
2970+
end
2971+
29572972
# issue 42220
29582973
macro m42220()
29592974
return quote

0 commit comments

Comments
 (0)