Julia: Consider warning about modules exporting undefined variables

Created on 4 Apr 2017  路  6Comments  路  Source: JuliaLang/julia

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.

modules

Most helpful comment

I just ran into this and found it surprising.

All 6 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

i-apellaniz picture i-apellaniz  路  3Comments

tkoolen picture tkoolen  路  3Comments

Keno picture Keno  路  3Comments

m-j-w picture m-j-w  路  3Comments

ararslan picture ararslan  路  3Comments