Skip to content

Commit 6c244b8

Browse files
authored
[JuliaLowering] Fix identifier -> GlobalRef conversion (#61521)
1 parent 9899954 commit 6c244b8

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

JuliaLowering/src/compat.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,7 @@ function est_to_dst(st::SyntaxTree)
450450
r3 -> @ast g st [K"." rec(l) r3]
451451
end
452452
end
453-
[K"inert" [K"Identifier"]] -> @ast g st st[1]=>K"Symbol"
454-
# [K"quote" [K"Identifier"]] -> @ast g st st[1]=>K"Symbol"
453+
([K"inert" [K"Identifier"]], when=!hasattr(st[1], :mod)) -> @ast g st st[1]=>K"Symbol"
455454
[K"inert" _] -> st
456455
[K"inert_syntaxtree" _] -> st
457456
[K"module" _...] -> st

JuliaLowering/test/macros.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,3 +881,28 @@ end
881881
mac_st = JuliaLowering.expr_to_est(mac_ex, LineNumberNode(1, "badfile"))
882882
@test JuliaLowering.eval(test_mod, mac_st) == "none"
883883
end
884+
885+
@testset "macro QuoteNode + inert behavior" begin
886+
Base.include_string(test_mod, raw"""
887+
macro quoted_gr()
888+
QuoteNode(GlobalRef(Base, :dontresolveme))
889+
end
890+
""")
891+
let gr = JuliaLowering.include_string(test_mod, "@quoted_gr")
892+
@test gr.mod === Base
893+
@test gr.name === :dontresolveme
894+
end
895+
end
896+
897+
@testset "Base macros" begin
898+
jl_eval(test_mod,
899+
:(function test_invokelatest()
900+
@eval invokelatest_target(x, y) = x + y
901+
out = @invokelatest(invokelatest_target(1, 2))
902+
Base.delete_binding(@__MODULE__, :invokelatest_target)
903+
out
904+
end))
905+
# the following test needs to define this to be effective
906+
@test_throws UndefVarError JuliaLowering.include_string(test_mod, "invokelatest_target(1,2)")
907+
@test JuliaLowering.include_string(test_mod, "test_invokelatest()") === 3
908+
end

0 commit comments

Comments
 (0)