julia
57bf0fb0 - [JuliaLowering] Force `GlobalRef` for function-returning macro (#62565)

Commit
5 days ago
[JuliaLowering] Force `GlobalRef` for function-returning macro (#62565) Implements the bug from #32026. I was incorrect before about function-name hygiene; I thought global unescaped function definitions were put in the macro-definition module on purpose, but that doesn't happen when wrapping the function in any other node*. It looks like `find-assigned-vars-in-expansion` completely misses the name of the function being defined when the definition is "outermost", so the name resolves like any other unresolved reference (including when the expansion is nested in some function definition.) ```julia # macroexpand.scm doesn't know about f, so it's implicitly global julia> module M macro unescaped_function(x) :(function f(x); x; end) end end; @macroexpand M.@unescaped_function(0) :(function Main.M.f(var"#23#x") #= REPL[17]:3 =# #= REPL[17]:3 =# var"#23#x" end) # works OK in begin julia> module M macro unescaped_function(x) :(begin; function f(x); x; end; end) end end; @macroexpand M.@unescaped_function(0) quote #= REPL[18]:3 =# function var"#24#f"(var"#25#x") #= REPL[18]:3 =# #= REPL[18]:3 =# var"#25#x" end end # macroexpand.scm doesn't care if it's in outer_func julia> module M macro unescaped_function(x) :(function f(x); x; end) end end; @macroexpand function outer_func(); M.@unescaped_function(0); end :(function outer_func() #= REPL[19]:5 =# #= REPL[19]:5 =# function Main.M.f(var"#26#x") #= REPL[19]:3 =# #= REPL[19]:3 =# var"#26#x" end end) ```
Author
Parents
Loading