Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transitively register local modules in ScoperState #2655

Merged
merged 3 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"};
Loading