Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Globals are not accessible right after Module() creation #57466

Open
serenity4 opened this issue Feb 19, 2025 · 3 comments
Open

Globals are not accessible right after Module() creation #57466

serenity4 opened this issue Feb 19, 2025 · 3 comments

Comments

@serenity4
Copy link
Contributor

In 1.11, we have

julia> Module().String
String

And on nightly:

julia> Module().String
ERROR: UndefVarError: `String` not defined in `Main.anonymous`
Suggestion: check for spelling errors or missing imports.
Hint: a global variable of this name also exists in Base.

which I have seen trigger a few errors, such as

Failed to precompile VSCodeServer [9f5989ce-84fe-42d4-91ec-6a7a8d53ed0f] to "/home/serenity4/.julia/compiled/v1.13/VSCodeServer/jl_GTnvEA" (ProcessExited(1)).
WARNING: Detected access to binding `Private.private` in a world prior to its definition world.
  Julia 1.12 has introduced more strict world age semantics for global bindings.
  !!! This code may malfunction under Revise.
  !!! This code will error in future versions of Julia.
Hint: Add an appropriate `invokelatest` around the access to this binding.
ERROR: LoadError: UndefVarError: `String` not defined in `VSCodeServer.JuliaInterpreter.var"#Internal".Private`
Suggestion: check for spelling errors or missing imports.
Hint: a global variable of this name also exists in Base.

It seems like a world age issue:

julia> function fails()
         m = Module()
         m.String
       end
fails (generic function with 1 method)

julia> fails()
ERROR: UndefVarError: `String` not defined in `Main.anonymous`
Suggestion: check for spelling errors or missing imports.
Hint: a global variable of this name also exists in Base.
Stacktrace:
 [1] getproperty
   @ ./Base_compiler.jl:48 [inlined]
 [2] fails()
   @ Main ./REPL[18]:3
 [3] top-level scope
   @ REPL[19]:1
 [4] top-level scope
   @ REPL:1

julia> function works()
         m = Module()
         @invokelatest m.String
       end
works (generic function with 1 method)

julia> works()
String

julia> m = Module()
Main.anonymous

julia> names(m; all=true, usings=true)
1227-element Vector{Symbol}:
 :!
 ...
@vtjnash
Copy link
Member

vtjnash commented Feb 19, 2025

using Module() in a local scope is not really valid code, so that is expected to give weird results

Anyways, something seems wrong though, since eval is missing in v1.12 despite being documented as being there:

julia> M = Module(); @invokelatest getglobal(M, :eval)
ERROR: UndefVarError: `eval` not defined in `Main.anonymous`

@serenity4
Copy link
Contributor Author

My understanding is that it's relied upon a fair bit (Infiltrator.jl also does that for example, and I worked on an industrial codebase that did the same in the past), and so might be quite breaking in practice.

@Seelengrab
Copy link
Contributor

Seelengrab commented Feb 20, 2025

I agree - it's quite surprising to hear that calling a documented constructor in a local scope is invalid. Are modules only supposed to be created by the compiler/runtime, directly from parsed code? If this always was invalid due to Module being special, why does the language allow this in the first place?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants