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.
push!(LOAD_PATH, @__DIR__) using A Core.eval(A, :(struct Foo end)) # B should be evaluated after A was modified using B
module A end
module B using A function func1(value::A.Foo) end end
ERROR: LoadError: UndefVarError: Foo not defined Stacktrace:  getproperty(::Module, ::Symbol) at ./sysimg.jl:13  top-level scope at none:0  include at ./boot.jl:326 [inlined]  include_relative(::Module, ::String) at ./loading.jl:1038  include(::Module, ::String) at ./sysimg.jl:29  top-level scope at none:2  eval at ./boot.jl:328 [inlined]  eval(::Expr) at ./client.jl:404  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:  error(::String) at ./error.jl:33  compilecache(::Base.PkgId, ::String) at ./loading.jl:1197  _require(::Base.PkgId) at ./loading.jl:960  require(::Base.PkgId) at ./loading.jl:858  require(::Module, ::Symbol) at ./loading.jl:853  include at ./boot.jl:326 [inlined]  include_relative(::Module, ::String) at ./loading.jl:1038  include(::Module, ::String) at ./sysimg.jl:29  exec_options(::Base.JLOptions) at ./client.jl:267  _start() at ./client.jl:436 in expression starting at /home/xxx/Documents/julia-bug-01-min-example/main.jl:8