git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Fix #178 - make sure qualified names are taken into account when sorting definitions.
commitb1ba4c2228d31e559c90ff1043b6530890f0d90a authorPhil Freeman <paf31@cantab.net> dateFri 7 Feb 2014, 17:06 (13 years ago) parent07afa04
2 files changed+18−6
examples/passing/TypeClassesInOrder.purs+11 src/Language/PureScript/Sugar/BindingGroups.hs+7−6
examples/passing/TypeClassesInOrder.pursnew file+11
@@ -0,0 +1,11 @@
1+module Main where
2+
3+import Prelude
4+
5+class Foo a where
6+ foo :: a -> String
7+
8+instance Foo String where
9+ foo s = s
10+
11+main = Trace.trace $ foo "Done"
src/Language/PureScript/Sugar/BindingGroups.hs+7−6
@@ -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]