For a project I’m currently working on I have to do a lot of code generation. I run into a problem when I tried to create structs at runtime and use them in method definitions as argument types. It would be great if someone knows some kind of workaround for this problem or has an explanation for this behaviour. I created a minimal example to illustrate the problem.
main
push!(LOAD_PATH, @__DIR__)
using A
Core.eval(A, :(struct Foo end))
# B should be evaluated after A was modified
using B
A.jl
module A end
B.jl
module B
using A
function func1(value::A.Foo) end
end
Error message
ERROR: LoadError: UndefVarError: Foo not defined
Stacktrace:
[1] getproperty(::Module, ::Symbol) at ./sysimg.jl:13
[2] top-level scope at none:0
[3] include at ./boot.jl:326 [inlined]
[4] include_relative(::Module, ::String) at ./loading.jl:1038
[5] include(::Module, ::String) at ./sysimg.jl:29
[6] top-level scope at none:2
[7] eval at ./boot.jl:328 [inlined]
[8] eval(::Expr) at ./client.jl:404
[9] top-level scope at ./none:3
in expression starting at /home/xxx/Documents/julia-bug-01-min-example/B.jl:3
ERROR: LoadError: Failed to precompile B [top-level] to /home/xxx/.julia/compiled/v1.1/B.ji.
Stacktrace:
[1] error(::String) at ./error.jl:33
[2] compilecache(::Base.PkgId, ::String) at ./loading.jl:1197
[3] _require(::Base.PkgId) at ./loading.jl:960
[4] require(::Base.PkgId) at ./loading.jl:858
[5] require(::Module, ::Symbol) at ./loading.jl:853
[6] include at ./boot.jl:326 [inlined]
[7] include_relative(::Module, ::String) at ./loading.jl:1038
[8] include(::Module, ::String) at ./sysimg.jl:29
[9] exec_options(::Base.JLOptions) at ./client.jl:267
[10] _start() at ./client.jl:436
in expression starting at /home/xxx/Documents/julia-bug-01-min-example/main.jl:8