@@ -36,7 +36,7 @@ import Language.PureScript.Types
3636-- Replace all sets of mutually-recursive declarations in a module with binding groups
3737--
3838createBindingGroupsModule :: [Module] -> Either String [Module]
39−createBindingGroupsModule = mapM $ \(Module name ds) -> Module name <$> createBindingGroups ds
39+createBindingGroupsModule = mapM $ \(Module name ds) -> Module name <$> createBindingGroups (ModuleName name) ds
4040
4141-- |
4242-- Collapse all binding groups in a module to individual declarations
@@ -47,15 +47,15 @@ collapseBindingGroupsModule = map $ \(Module name ds) -> Module name (collapseBi
4747-- |
4848-- Replace all sets of mutually-recursive declarations with binding groups
4949--
50−createBindingGroups :: [Declaration] -> Either String [Declaration]
51−createBindingGroups ds = do
50+createBindingGroups :: ModuleName -> [Declaration] -> Either String [Declaration]
51+createBindingGroups moduleName ds = do
5252 let values = filter isValueDecl ds
5353 dataDecls = filter isDataDecl ds
5454 allProperNames = map getProperName dataDecls
5555 dataVerts = map (\d -> (d, getProperName d, usedProperNames d `intersect` allProperNames)) dataDecls
5656 dataBindingGroupDecls <- mapM toDataBindingGroup $ stronglyConnComp dataVerts
5757 let allIdents = map getIdent values
58− valueVerts = map (\d -> (d, getIdent d, usedIdents d `intersect` allIdents)) values
58+ valueVerts = map (\d -> (d, getIdent d, usedIdents moduleName d `intersect` allIdents)) values
5959 bindingGroupDecls = map toBindingGroup $ stronglyConnComp valueVerts
6060 return $ filter isImportDecl ds ++
6161 filter isExternDataDecl ds ++
@@ -75,11 +75,12 @@ collapseBindingGroups ds = concatMap go ds
7575 go (BindingGroupDeclaration ds) = map (\(ident, val) -> ValueDeclaration ident [] Nothing val) ds
7676 go other = [other]
7777
78−usedIdents :: (Data d) => d -> [Ident]
79−usedIdents = nub . everything (++) (mkQ [] names)
78+usedIdents :: (Data d) => ModuleName -> d -> [Ident]
79+usedIdents moduleName = nub . everything (++) (mkQ [] names)
8080 where
8181 names :: Value -> [Ident]
8282 names (Var (Qualified Nothing name)) = [name]
83+ names (Var (Qualified (Just moduleName') name)) | moduleName == moduleName' = [name]
8384 names _ = []
8485
8586usedProperNames :: (Data d) => d -> [ProperName]