Skip to content

Commit eaf876e

Browse files
fixes
1 parent 33fa827 commit eaf876e

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

base/loading.jl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2251,13 +2251,19 @@ end
22512251
22522252
Checks that a package entry file `srcpath` has a module declaration, and that it is before any using/import statements.
22532253
"""
2254-
function check_src_module_wrap(srcpath::String)
2254+
function check_src_module_wrap(pkg::PkgId, srcpath::String)
22552255
module_rgx = r"^\s*(?:@\w*\s*)*(?:bare)?module\s"
22562256
load_rgx = r"\b(?:using|import)\s"
2257+
load_seen = false
22572258
for s in eachline(srcpath)
2258-
contains(s, module_rgx) && return
2259+
if contains(s, module_rgx)
2260+
if load_seen
2261+
throw(ErrorException("Package $pkg source file $input has a using/import before a module declaration."))
2262+
end
2263+
return
2264+
end
22592265
if contains(s, load_rgx)
2260-
throw(ErrorException("Package $pkg source file $input has a using/import before a module declaration."))
2266+
load_seen = true
22612267
end
22622268
end
22632269
throw(ErrorException("Package $pkg source file $input does not contain a module declaration."))
@@ -2267,7 +2273,7 @@ end
22672273
function include_package_for_output(pkg::PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String},
22682274
concrete_deps::typeof(_concrete_dependencies), source::Union{Nothing,String})
22692275

2270-
check_src_module_wrap(input)
2276+
check_src_module_wrap(pkg, input)
22712277

22722278
append!(empty!(Base.DEPOT_PATH), depot_path)
22732279
append!(empty!(Base.DL_LOAD_PATH), dl_load_path)

0 commit comments

Comments
 (0)