Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth committed Oct 9, 2023
1 parent 33fa827 commit eaf876e
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2251,13 +2251,19 @@ end
Checks that a package entry file `srcpath` has a module declaration, and that it is before any using/import statements.
"""
function check_src_module_wrap(srcpath::String)
function check_src_module_wrap(pkg::PkgId, srcpath::String)
module_rgx = r"^\s*(?:@\w*\s*)*(?:bare)?module\s"
load_rgx = r"\b(?:using|import)\s"
load_seen = false
for s in eachline(srcpath)
contains(s, module_rgx) && return
if contains(s, module_rgx)
if load_seen
throw(ErrorException("Package $pkg source file $input has a using/import before a module declaration."))
end
return
end
if contains(s, load_rgx)
throw(ErrorException("Package $pkg source file $input has a using/import before a module declaration."))
load_seen = true
end
end
throw(ErrorException("Package $pkg source file $input does not contain a module declaration."))
Expand All @@ -2267,7 +2273,7 @@ end
function include_package_for_output(pkg::PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String},
concrete_deps::typeof(_concrete_dependencies), source::Union{Nothing,String})

check_src_module_wrap(input)
check_src_module_wrap(pkg, input)

append!(empty!(Base.DEPOT_PATH), depot_path)
append!(empty!(Base.DL_LOAD_PATH), dl_load_path)
Expand Down

0 comments on commit eaf876e

Please sign in to comment.