This may or may not be a bug, I’m not sure - but as a workaround, you can just esc the entire expression returned by your macro and it seems to work.
If you don’t need macro hygiene anywhere, you don’t need to do targeted esc’s like that.
macro make_struct(arg)
esc(quote
struct $arg
x
end
export $arg
end
)
end
julia> @macroexpand @make_many_structs
quote
#= REPL[9]:3 =#
begin
#= REPL[6]:3 =#
struct Foo
#= REPL[6]:4 =#
x
end
#= REPL[6]:6 =#
export Foo
end
begin
#= REPL[6]:3 =#
struct Bar
#= REPL[6]:4 =#
x
end
#= REPL[6]:6 =#
export Bar
end
end