Skip to content

Commit 2ec9a59

Browse files
committed
fix: allow mixing modules and non-modules when root is not a module
1 parent 54c12df commit 2ec9a59

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/Lean/Environment.lean

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,7 +1878,13 @@ private def findOLeanParts (mod : Name) : IO (Array System.FilePath) := do
18781878

18791879
partial def importModulesCore
18801880
(imports : Array Import) (isModule := false) (arts : NameMap ModuleArtifacts := {}) :
1881-
ImportStateM Unit := go imports (importAll := true) (isExported := isModule)
1881+
ImportStateM Unit := do
1882+
go imports (importAll := true) (isExported := isModule)
1883+
if isModule then
1884+
for i in imports do
1885+
if let some mod := (← get).moduleNameMap[i.module]?.bind (·.mainModule?) then
1886+
if !mod.isModule then
1887+
throw <| IO.userError s!"cannot import non`-module` {i.module} from `module`"
18821888
/-
18831889
When the module system is disabled for the root, we import all transitively referenced modules and
18841890
ignore any module system annotations on the way.
@@ -1950,11 +1956,6 @@ where go (imports : Array Import) (importAll : Bool) (isExported : Bool) := do
19501956
-- `imports` is identical for each part
19511957
let some (baseMod, _) := parts[0]? | unreachable!
19521958
goRec baseMod.imports
1953-
if baseMod.isModule && isModule then
1954-
for i' in imports do
1955-
if let some mod := (← get).moduleNameMap[i'.module]?.bind (·.mainModule?) then
1956-
if !mod.isModule then
1957-
throw <| IO.userError s!"cannot import non`-module` {i'.module} from `module` {i.module}"
19581959
modify fun s => { s with
19591960
moduleNameMap := s.moduleNameMap.insert i.module { i with importAll, isExported, parts }
19601961
moduleNames := s.moduleNames.push i.module

0 commit comments

Comments
 (0)