Skip to content

Commit 52a225d

Browse files
allow more module tag formats in module check
1 parent 86cbb60 commit 52a225d

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

base/loading.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2252,7 +2252,7 @@ end
22522252
Checks that a package entry file `srcpath` has a module declaration, and that it is before any using/import statements.
22532253
"""
22542254
function check_src_module_wrap(pkg::PkgId, srcpath::String)
2255-
module_rgx = r"^\s*(?:@\w*\s*)*(?:bare)?module\s"
2255+
module_rgx = r"\s*(?:@\w*\s*)*(?:bare)?module\s"
22562256
load_rgx = r"\b(?:using|import)\s"
22572257
load_seen = false
22582258
inside_string = false
@@ -2262,7 +2262,7 @@ function check_src_module_wrap(pkg::PkgId, srcpath::String)
22622262
inside_string = !inside_string
22632263
end
22642264
inside_string && continue
2265-
if startswith(s, module_rgx)
2265+
if contains(s, module_rgx)
22662266
if load_seen
22672267
throw(ErrorException("Package $pkg source file $srcpath has a using/import before a module declaration."))
22682268
end

test/loading.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,24 @@ end
12221222
""")
12231223
@test Base.check_src_module_wrap(p, fpath)
12241224

1225+
write(fpath, """
1226+
\"\"\"
1227+
Foo
1228+
\"\"\" module Foo
1229+
using Bar
1230+
end
1231+
""")
1232+
@test Base.check_src_module_wrap(p, fpath)
1233+
1234+
write(fpath, """
1235+
@doc let x = 1
1236+
x
1237+
end module Foo
1238+
using Bar
1239+
end
1240+
""")
1241+
@test Base.check_src_module_wrap(p, fpath)
1242+
12251243
write(fpath, """
12261244
# using foo
12271245
module Foo

0 commit comments

Comments
 (0)