Skip to content

Commit

Permalink
Transitively register local modules in ScoperState (#2655)
Browse files Browse the repository at this point in the history
This PR fixes a TODO in the scoper code. We need to transitively
register local modules when checking an import.


* Closes #2654
  • Loading branch information
paulcadman authored Feb 16, 2024
1 parent a110297 commit dc04989
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion test/Scope/Positive.hs
Original file line number Diff line number Diff line change
Expand Up @@ -233,5 +233,9 @@ tests =
"Package file"
$(mkRelDir "package")
$(mkRelFile "Package.juvix")
PackagePathResolver
PackagePathResolver,
posTest
"Import nested local module"
$(mkRelDir "ImportNestedLocalModule")
$(mkRelFile "ImportNestedLocalModule.juvix")
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module ImportNestedLocalModule;

import Stdlib.Prelude open;
import ImportedModule open;

main : Nat := ImportedModule.A.B.x;
11 changes: 11 additions & 0 deletions tests/positive/ImportNestedLocalModule/ImportedModule.juvix
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module ImportedModule;

import Stdlib.Prelude open;

module A;

module B;
x : Nat := 1;
end;

end;
5 changes: 5 additions & 0 deletions tests/positive/ImportNestedLocalModule/Package.juvix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Package;

import PackageDescription.V2 open;

package : Package := defaultPackage {name := "test074"};

0 comments on commit dc04989

Please sign in to comment.