Skip to content
Merged
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: 2 additions & 2 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2252,7 +2252,7 @@ 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(pkg::PkgId, srcpath::String)
module_rgx = r"^\s*(?:@\w*\s*)*(?:bare)?module\s"
module_rgx = r"^(|end |\"\"\" )\s*(?:@)*(?:bare)?module\s"
load_rgx = r"\b(?:using|import)\s"
load_seen = false
inside_string = false
Expand All @@ -2262,7 +2262,7 @@ function check_src_module_wrap(pkg::PkgId, srcpath::String)
inside_string = !inside_string
end
inside_string && continue
if startswith(s, module_rgx)
if contains(s, module_rgx)
if load_seen
throw(ErrorException("Package $pkg source file $srcpath has a using/import before a module declaration."))
end
Expand Down
14 changes: 12 additions & 2 deletions test/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1223,8 +1223,18 @@ end
@test Base.check_src_module_wrap(p, fpath)

write(fpath, """
# using foo
module Foo
\"\"\"
Foo
\"\"\" module Foo
using Bar
end
""")
@test Base.check_src_module_wrap(p, fpath)

write(fpath, """
@doc let x = 1
x
end module Foo
using Bar
end
""")
Expand Down