diff --git a/base/loading.jl b/base/loading.jl index 4eca0ea0e1200..25fe8144b71d6 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -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 @@ -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 diff --git a/test/loading.jl b/test/loading.jl index d7e967f209eaa..0ee3e3985cc84 100644 --- a/test/loading.jl +++ b/test/loading.jl @@ -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 """)