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
4 changes: 4 additions & 0 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2383,6 +2383,10 @@ function __require(into::Module, mod::Symbol)
error("`using/import $mod` outside of a Module detected. Importing a package outside of a module \
is not allowed during package precompilation.")
end
topmod = moduleroot(into)
if nameof(topmod) === mod
return topmod
end
@lock require_lock begin
LOADING_CACHE[] = LoadingCache()
try
Expand Down
15 changes: 15 additions & 0 deletions test/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2360,4 +2360,19 @@ precompile_test_harness("MainImportDisallow") do load_path
end
end

precompile_test_harness("Package top-level load itself") do load_path
write(joinpath(load_path, "UsingSelf.jl"),
"""
__precompile__(false)
module UsingSelf
using UsingSelf
x = 3
end
""")
@eval using UsingSelf
invokelatest() do
@test UsingSelf.x == 3
end
end

finish_precompile_test!()