JuliaPackaging / Requires.jl

Lazy code loading for Julia
Other
195 stars 28 forks source link

`@eval` interpolation broken inside `@require` block #86

Open marius311 opened 4 years ago

marius311 commented 4 years ago

A MWE with Julia 1.4.2 and Requires v1.0.1:

julia> using Requires

julia> @require Requires="ae029012-a4dd-5104-9daa-d747884805df" begin
           x = 2
           @eval $x
       end
ERROR: UndefVarError: x not defined
mcabbott commented 4 years ago

I think this is a more general problem with macros being expanded before the package is loaded, I've run into it when e.g. calling Zygote.@adjoint within a block. Moving the code into a file is a work-around:

julia> using Requires

shell> cat test.jl
x = 2
@eval $x

julia> @require Requires="ae029012-a4dd-5104-9daa-d747884805df" begin
           include("test.jl")
       end
2

julia> @require Requires="ae029012-a4dd-5104-9daa-d747884805df" begin
           x = 2
           @eval $x
       end
ERROR: UndefVarError: x not defined