diff --git a/base/loading.jl b/base/loading.jl index e7ff3abc13fb0..68fe297fadff3 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -2224,7 +2224,7 @@ function __require_prelocked(uuidkey::PkgId, env=nothing) run_package_callbacks(uuidkey) else m = get(loaded_modules, uuidkey, nothing) - if m !== nothing + if m !== nothing && !haskey(explicit_loaded_modules, uuidkey) explicit_loaded_modules[uuidkey] = m run_package_callbacks(uuidkey) end diff --git a/test/precompile.jl b/test/precompile.jl index 2873cb351665f..ed341d0624796 100644 --- a/test/precompile.jl +++ b/test/precompile.jl @@ -1363,6 +1363,25 @@ precompile_test_harness("package_callbacks") do dir finally pop!(Base.package_callbacks) end + Test5_module = :Teste4095a85 + write(joinpath(dir, "$(Test5_module).jl"), + """ + module $(Test5_module) + end + """) + Base.compilecache(Base.PkgId("$(Test5_module)")) + cnt = 0 + push!(Base.package_callbacks, _->(cnt += 1)) + try + @eval using $(Symbol(Test5_module)) + @eval using $(Symbol(Test5_module)) + @eval using $(Symbol(Test5_module)) + @eval using $(Symbol(Test5_module)) + @eval using $(Symbol(Test5_module)) + @test cnt == 1 + finally + pop!(Base.package_callbacks) + end end # Issue #19960