simonster / Reexport.jl

Julia macro for re-exporting one module from another
Other
161 stars 19 forks source link

The Macro "@reexport" Fails in Modules Declared with "baremodule" #32

Closed Acmion closed 3 years ago

Acmion commented 3 years ago

Decorating your modules with baremodule (which does not import Base by default) will cause @reexport to fail with the following error:

ERROR: LoadError: UndefVarError: names not defined
Stacktrace:
 [1] top-level scope
   @ actual\b.jl:3
 [2] include(m::Module, fname::String)
   @ Core .\boot.jl:358
 [3] top-level scope
   @ none:1
in expression starting at actual/b.jl:3

Examples

The following code works:

module b
    using Reexport
    @reexport using BenchmarkTools
end

The following code does not work:

baremodule b
    using Reexport
    @reexport using BenchmarkTools
end

Potential Solution In Reexport.jl/src/Reexport.jl you could refer to Reexport.Base.names rather than to names. This will work with a relatively high probability, since the module Reexport would have to be imported in each context where it is to be used and as such we can qualify Base using the module name.

However, this approach could still fail if someone would import this module followingly:

using Reexport as Re

I suppose that the root cause of this problem is the eval statement in the expression returned by the @reexport macro. Maybe it would be easier to fix the problem there?

ararslan commented 3 years ago

Thanks for the report! I have a fix in #33.