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.
b1ba4c2Phil Freeman
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
36-- Replace all sets of mutually-recursive declarations in a module with binding groups
36-- Replace all sets of mutually-recursive declarations in a module with binding groups
37--
37--
38createBindingGroupsModule :: [Module] -> Either String [Module]
38createBindingGroupsModule :: [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
40
40
41-- |
41-- |
42-- Collapse all binding groups in a module to individual declarations
42-- Collapse all binding groups in a module to individual declarations
@@ -47,15 +47,15 @@ collapseBindingGroupsModule = map $ \(Module name ds) -> Module name (collapseBi
47-- |
47-- |
48-- Replace all sets of mutually-recursive declarations with binding groups
48-- Replace all sets of mutually-recursive declarations with binding groups
49--
49--
50−createBindingGroups :: [Declaration] -> Either String [Declaration]
50+createBindingGroups :: ModuleName -> [Declaration] -> Either String [Declaration]
51−createBindingGroups ds = do
51+createBindingGroups moduleName ds = do
52 let values = filter isValueDecl ds
52 let values = filter isValueDecl ds
53 dataDecls = filter isDataDecl ds
53 dataDecls = filter isDataDecl ds
54 allProperNames = map getProperName dataDecls
54 allProperNames = map getProperName dataDecls
55 dataVerts = map (\d -> (d, getProperName d, usedProperNames d `intersect` allProperNames)) dataDecls
55 dataVerts = map (\d -> (d, getProperName d, usedProperNames d `intersect` allProperNames)) dataDecls
56 dataBindingGroupDecls <- mapM toDataBindingGroup $ stronglyConnComp dataVerts
56 dataBindingGroupDecls <- mapM toDataBindingGroup $ stronglyConnComp dataVerts
57 let allIdents = map getIdent values
57 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
59 bindingGroupDecls = map toBindingGroup $ stronglyConnComp valueVerts
59 bindingGroupDecls = map toBindingGroup $ stronglyConnComp valueVerts
60 return $ filter isImportDecl ds ++
60 return $ filter isImportDecl ds ++
61 filter isExternDataDecl ds ++
61 filter isExternDataDecl ds ++
@@ -75,11 +75,12 @@ collapseBindingGroups ds = concatMap go ds
75 go (BindingGroupDeclaration ds) = map (\(ident, val) -> ValueDeclaration ident [] Nothing val) ds
75 go (BindingGroupDeclaration ds) = map (\(ident, val) -> ValueDeclaration ident [] Nothing val) ds
76 go other = [other]
76 go other = [other]
77
77
78−usedIdents :: (Data d) => d -> [Ident]
78+usedIdents :: (Data d) => ModuleName -> d -> [Ident]
79−usedIdents = nub . everything (++) (mkQ [] names)
79+usedIdents moduleName = nub . everything (++) (mkQ [] names)
80 where
80 where
81 names :: Value -> [Ident]
81 names :: Value -> [Ident]
82 names (Var (Qualified Nothing name)) = [name]
82 names (Var (Qualified Nothing name)) = [name]
83+ names (Var (Qualified (Just moduleName') name)) | moduleName == moduleName' = [name]
83 names _ = []
84 names _ = []
84
85
85usedProperNames :: (Data d) => d -> [ProperName]
86usedProperNames :: (Data d) => d -> [ProperName]