Currently it is possible to export symbols in a module which are never defined.
Accordingly, names(module)
returns these exports, but getfield(module, symbol)
throws.
julia> module M
export variable
end
names(M) |> println
getfield(M,:variable)
Symbol[:M, :variable]
ERROR: UndefVarError: variable not defined
As mentioned in the discussion of #21217, in particular https://github.com/JuliaLang/julia/pull/21217#issuecomment-290098823 , an option might be to give a warning in an initial module definition (as shown above) if such a condition is detected. However, this would still allow to eval
later on without such checks.
Currently, such a test would give warnings in Base due to platform dependent symbols.
I don't consider this a priority issue, but should be kept in mind for future improvement.
This will also cause warning for variables defined in __init__
.
Note that Lint.jl can warn for this.
Since we automatically call __init__
when loading a module, why not just run the check after that?
I just ran into this and found it surprising.
Interesting that this conversation just died. I have asked myself why there is not a warning for this a few times.
I still think the check after running __init__
seems like a good idea.
Most helpful comment
I just ran into this and found it surprising.