Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Language changes
is considered a bug fix ([#47102])

- The `hash` algorithm and its values have changed. Most `hash` specializations will remain correct and require no action. Types that reimplement the core hashing logic independently, such as some third-party string packages do, may require a migration to the new algorithm. ([#57509])
- `using Foo: _` for a module or package `Foo` no longer issues a warning. This syntax can be used to load `Foo` without bringing any of its names (even the name `Foo` itself) into your namespace.

Compiler/Runtime improvements
-----------------------------
Expand Down
13 changes: 9 additions & 4 deletions src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -1232,10 +1232,15 @@ JL_DLLEXPORT void jl_module_import(jl_task_t *ct, jl_module_t *to, jl_module_t *
jl_walk_binding_inplace(&ownerb, &ownerbpart, ct->world_age);

if (jl_bkind_is_some_guard(jl_binding_kind(ownerbpart))) {
jl_printf(JL_STDERR,
"WARNING: Imported binding %s.%s was undeclared at import time during import to %s.\n",
jl_symbol_name(from->name), jl_symbol_name(s),
jl_symbol_name(to->name));
if (strcmp(jl_symbol_name(s), "_") == 0) {
// importing `_` loads the package but does not import a binding
return;
} else {
jl_printf(JL_STDERR,
"WARNING: Imported binding %s.%s was undeclared at import time during import to %s.\n",
jl_symbol_name(from->name), jl_symbol_name(s),
jl_symbol_name(to->name));
}
}

jl_binding_t *bto = jl_get_module_binding(to, asname, 1);
Expand Down
13 changes: 13 additions & 0 deletions test/syntax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2752,6 +2752,19 @@ import .TestImportAs.Mod2 as M2
@test !@isdefined(Mod2)
@test M2 === TestImportAs.Mod2

# `using Foo: _` is special cased to not warn so it can be used to load
# a module only for its side effects. (#58667)
side_effect_triggered = Ref(false)
module Mod58667
__init__() = (parentmodule(@__MODULE__).side_effect_triggered[] = true; nothing)
end
@test_nowarn using .Mod58667: _
@test side_effect_triggered[] # module was loaded!
# does not warn if you import again:
@test_nowarn using .Mod58667: _
# but importing a non-existent non-`_` binding does warn:
@test_warn "WARNING: Imported binding Mod58667.y was undeclared at import time during import to Main." using .Mod58667: y

# 57702: nearby bindings shouldn't cause us to closure-convert in import/using
module OddImports
using Test
Expand Down