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

using creates explicit bindings inconsistently #52817

Open
LilithHafner opened this issue Jan 8, 2024 · 1 comment · May be fixed by #52821
Open

using creates explicit bindings inconsistently #52817

LilithHafner opened this issue Jan 8, 2024 · 1 comment · May be fixed by #52821

Comments

@LilithHafner
Copy link
Member

julia> module M1 module M2 end end
Main.M1

julia> using .M1.M2

julia> using Statistics

julia> names(Main, imported=true)
5-element Vector{Symbol}:
 :Base
 :Core
 :M1
 :Main
 :Statistics

julia> module M3
           using Statistics
       end
Main.M3

julia> names(M3, imported=true)
1-element Vector{Symbol}:
 :M3

This is due to

julia/src/toplevel.c

Lines 771 to 775 in b354ce7

if (m == jl_main_module && name == NULL) {
// TODO: for now, `using A` in Main also creates an explicit binding for `A`
// This will possibly be extended to all modules.
import_module(m, u, NULL);
}

Which I think was added 7 years ago in #25256

@LilithHafner
Copy link
Member Author

A more significant consequence of this is:

julia> Statistics = 4
4

julia> using Statistics
WARNING: using Statistics.Statistics in module Main conflicts with an existing identifier.
ERROR: cannot declare Main.Statistics constant; it already has a value

julia> module M4
       Statistics = 5
       using Statistics
       end
WARNING: using Statistics.Statistics in module M4 conflicts with an existing identifier.
Main.M4

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

Successfully merging a pull request may close this issue.

1 participant