1
1
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:
Paul Cadman 2024-02-16 14:09:49 +00:00 committed by GitHub
parent a110297a69
commit dc0498902f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 33 additions and 5 deletions

View File

@ -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

View File

@ -233,5 +233,9 @@ tests =
"Package file"
$(mkRelDir "package")
$(mkRelFile "Package.juvix")
PackagePathResolver
PackagePathResolver,
posTest
"Import nested local module"
$(mkRelDir "ImportNestedLocalModule")
$(mkRelFile "ImportNestedLocalModule.juvix")
]

View File

@ -0,0 +1,6 @@
module ImportNestedLocalModule;
import Stdlib.Prelude open;
import ImportedModule open;
main : Nat := ImportedModule.A.B.x;

View File

@ -0,0 +1,11 @@
module ImportedModule;
import Stdlib.Prelude open;
module A;
module B;
x : Nat := 1;
end;
end;

View File

@ -0,0 +1,5 @@
module Package;
import PackageDescription.V2 open;
package : Package := defaultPackage {name := "test074"};