mirror of
https://github.com/anoma/juvix.git
synced 2024-11-30 14:13:27 +03:00
Transitively register local modules in ScoperState (#2655)
This PR fixes a TODO in the scoper code. We need to transitively register local modules when checking an import. * Closes #2654
This commit is contained in:
parent
a110297a69
commit
dc0498902f
@ -405,7 +405,6 @@ checkImport import_@Import {..} = do
|
||||
smodule <- readScopeModule import_
|
||||
let sname :: S.TopModulePath = smodule ^. scopedModulePath
|
||||
sname' :: S.Name = set S.nameConcrete (topModulePathToName _importModulePath) sname
|
||||
mid = sname ^. S.nameId
|
||||
cmodule = set scopedModuleName sname' smodule
|
||||
importName :: S.TopModulePath = set S.nameConcrete _importModulePath sname
|
||||
synonymName :: Maybe S.TopModulePath = do
|
||||
@ -418,9 +417,7 @@ checkImport import_@Import {..} = do
|
||||
addModuleToScope cmodule
|
||||
registerName importName
|
||||
whenJust synonymName registerName
|
||||
modify (over scoperModules (HashMap.insert mid cmodule))
|
||||
-- TODO: this needs to be transitive
|
||||
modify (over scoperModules (HashMap.union (cmodule ^. scopedModuleLocalModules)))
|
||||
registerScoperModules cmodule
|
||||
importOpen' <- mapM (checkImportOpenParams cmodule) _importOpen
|
||||
return
|
||||
Import
|
||||
@ -437,6 +434,11 @@ checkImport import_@Import {..} = do
|
||||
singTbl = HashMap.singleton uid smod
|
||||
modify (over (scopeTopModules . at mpath) (Just . maybe singTbl (HashMap.insert uid smod)))
|
||||
|
||||
registerScoperModules :: ScopedModule -> Sem r ()
|
||||
registerScoperModules m = do
|
||||
modify (over scoperModules (HashMap.insert (m ^. scopedModulePath . S.nameId) m))
|
||||
forM_ (m ^. scopedModuleLocalModules) registerScoperModules
|
||||
|
||||
getTopModulePath :: Module 'Parsed 'ModuleTop -> S.AbsModulePath
|
||||
getTopModulePath Module {..} =
|
||||
S.AbsModulePath
|
||||
|
@ -233,5 +233,9 @@ tests =
|
||||
"Package file"
|
||||
$(mkRelDir "package")
|
||||
$(mkRelFile "Package.juvix")
|
||||
PackagePathResolver
|
||||
PackagePathResolver,
|
||||
posTest
|
||||
"Import nested local module"
|
||||
$(mkRelDir "ImportNestedLocalModule")
|
||||
$(mkRelFile "ImportNestedLocalModule.juvix")
|
||||
]
|
||||
|
@ -0,0 +1,6 @@
|
||||
module ImportNestedLocalModule;
|
||||
|
||||
import Stdlib.Prelude open;
|
||||
import ImportedModule open;
|
||||
|
||||
main : Nat := ImportedModule.A.B.x;
|
11
tests/positive/ImportNestedLocalModule/ImportedModule.juvix
Normal file
11
tests/positive/ImportNestedLocalModule/ImportedModule.juvix
Normal file
@ -0,0 +1,11 @@
|
||||
module ImportedModule;
|
||||
|
||||
import Stdlib.Prelude open;
|
||||
|
||||
module A;
|
||||
|
||||
module B;
|
||||
x : Nat := 1;
|
||||
end;
|
||||
|
||||
end;
|
5
tests/positive/ImportNestedLocalModule/Package.juvix
Normal file
5
tests/positive/ImportNestedLocalModule/Package.juvix
Normal file
@ -0,0 +1,5 @@
|
||||
module Package;
|
||||
|
||||
import PackageDescription.V2 open;
|
||||
|
||||
package : Package := defaultPackage {name := "test074"};
|
Loading…
Reference in New Issue
Block a user