git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Fix #611 - do not take locally-bound names into account when calculating binding groups
02a7452Phil Freeman
examples/passing/BindingGroups.pursnew file+8
@@ -0,0 +1,8 @@
1+module Main where
2+
3+foo = bar
4+ where bar r = r + 1
5+
6+r = foo 2
7+
8+main = Debug.Trace.trace "Done"
src/Language/PureScript/Sugar/BindingGroups.hs+13−5
@@ -26,6 +26,8 @@ import Data.List (nub, intersect)
26import Data.Maybe (isJust, mapMaybe)
26import Data.Maybe (isJust, mapMaybe)
27import Control.Applicative ((<$>), (<*>), pure)
27import Control.Applicative ((<$>), (<*>), pure)
28
28
29+import qualified Data.Set as S
30+
29import Language.PureScript.Declarations
31import Language.PureScript.Declarations
30import Language.PureScript.Names
32import Language.PureScript.Names
31import Language.PureScript.Types
33import Language.PureScript.Types
@@ -91,13 +93,19 @@ collapseBindingGroupsForValue other = other
91
93
92usedIdents :: ModuleName -> Declaration -> [Ident]
94usedIdents :: ModuleName -> Declaration -> [Ident]
93usedIdents moduleName =
95usedIdents moduleName =
94− let (f, _, _, _, _) = everythingOnValues (++) (const []) usedNames (const []) (const []) (const [])
96+ let (f, _, _, _, _) = everythingWithContextOnValues S.empty [] (++) def usedNamesE usedNamesB def def
95 in nub . f
97 in nub . f
96 where
98 where
97− usedNames :: Expr -> [Ident]
99+ def s _ = (s, [])
100+
101+ usedNamesE :: S.Set Ident -> Expr -> (S.Set Ident, [Ident])
98− usedNames (Var (Qualified Nothing name)) = [name]
102+ usedNamesE scope (Var (Qualified Nothing name)) | name `S.notMember` scope = (scope, [name])
99− usedNames (Var (Qualified (Just moduleName') name)) | moduleName == moduleName' = [name]
103+ usedNamesE scope (Var (Qualified (Just moduleName') name)) | moduleName == moduleName' && name `S.notMember` scope = (scope, [name])
100− usedNames _ = []
104+ usedNamesE scope (Abs (Left name) _) = (name `S.insert` scope, [])
105+ usedNamesE scope _ = (scope, [])
106+
107+ usedNamesB :: S.Set Ident -> Binder -> (S.Set Ident, [Ident])
108+ usedNamesB scope binder = (scope `S.union` S.fromList (binderNames binder), [])
101
109
102usedProperNames :: ModuleName -> Declaration -> [ProperName]
110usedProperNames :: ModuleName -> Declaration -> [ProperName]
103usedProperNames moduleName =
111usedProperNames moduleName =