Skip to content

Commit

Permalink
Fix use of reexport inside of baremodules (#33)
Browse files Browse the repository at this point in the history
* Fix use of reexport inside of baremodules

As described in issue 32, the generated code from the macro included
references to `Base`, which notably is not defined in `baremodule`s. We
can get around this by moving the part that fetches and filters module
names into its own function, ensure that gets used as a `GlobalRef` by
the macro, and swap the `eval` for `Core.eval`, which is available in
`baremodule`s.

* Bump patch version
  • Loading branch information
ararslan committed Aug 24, 2021
1 parent 609c8fc commit fd87dbf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Reexport"
uuid = "189a3867-3050-52da-a836-e630ba90ab69"
authors = ["Simon Kornblith <simon@simonster.com>"]
version = "1.2.0"
version = "1.2.1"

[compat]
julia = "1"
Expand Down
12 changes: 8 additions & 4 deletions src/Reexport.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@ function reexport(m::Module, ex::Expr)
modules = Any[e.args[end] for e in ex.args]
end

Expr(:toplevel, ex,
[:(eval(Expr(:export, filter!(x -> Base.isexported($mod, x),
names($mod; all=true, imported=true))...)))
for mod in modules]...)
names = GlobalRef(@__MODULE__, :exported_names)
out = Expr(:toplevel, ex)
for mod in modules
push!(out.args, :(Core.eval($m, Expr(:export, $names($mod)...))))
end
return out
end

exported_names(m::Module) = filter!(x -> Base.isexported(m, x), names(m; all=true, imported=true))

export @reexport

end # module
8 changes: 8 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,11 @@ end
@test Set(names(X15)) == Set([:X15, :a])
end

baremodule B16
using Reexport
@reexport using Test
end
using .B16
@testset "baremodule" begin
@test Base.isexported(B16, Symbol("@test"))
end

0 comments on commit fd87dbf

Please sign in to comment.