diff --git a/src/module.c b/src/module.c index 4f21408fa7626..ea62a300ce56b 100644 --- a/src/module.c +++ b/src/module.c @@ -648,7 +648,7 @@ JL_DLLEXPORT jl_value_t *jl_module_names(jl_module_t *m, int all, int imported) int hidden = jl_symbol_name(b->name)[0]=='#'; if ((b->exportp || (imported && b->imported) || - ((b->owner == m) && (all || m == jl_main_module))) && + (b->owner == m && !b->imported && (all || m == jl_main_module))) && (all || (!b->deprecated && !hidden))) { jl_array_grow_end(a, 1); //XXX: change to jl_arrayset if array storage allocation for Array{Symbols,1} changes: diff --git a/src/toplevel.c b/src/toplevel.c index f718d2df401fd..c3279117dacbe 100644 --- a/src/toplevel.c +++ b/src/toplevel.c @@ -516,14 +516,23 @@ static jl_method_instance_t *method_instance_for_thunk(jl_code_info_t *src, jl_m static void import_module(jl_module_t *m, jl_module_t *import) { jl_sym_t *name = import->name; + jl_binding_t *b; if (jl_binding_resolved_p(m, name)) { - jl_binding_t *b = jl_get_binding(m, name); + b = jl_get_binding(m, name); if (b->owner != m || (b->value && b->value != (jl_value_t*)import)) { jl_errorf("importing %s into %s conflicts with an existing identifier", jl_symbol_name(name), jl_symbol_name(m->name)); } } - jl_set_const(m, name, (jl_value_t*)import); + else { + b = jl_get_binding_wr(m, name, 1); + b->imported = 1; + } + if (!b->constp) { + b->value = (jl_value_t*)import; + b->constp = 1; + jl_gc_wb(m, (jl_value_t*)import); + } } // replace Base.X with top-level X diff --git a/test/reflection.jl b/test/reflection.jl index 38efa48b72f57..dbb544b2e8ac1 100644 --- a/test/reflection.jl +++ b/test/reflection.jl @@ -738,3 +738,12 @@ typeparam(::Type{T}, a::AbstractArray{T}) where T = 2 @test typeparam(Int, rand(Int, 2)) == 2 end + +# issue #26267 +module M26267 +import Test +foo(x) = x +end +@test !(:Test in names(M26267, all=true, imported=false)) +@test :Test in names(M26267, all=true, imported=true) +@test :Test in names(M26267, all=false, imported=true)