git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #636 from purescript/611

Fix #611 - do not take locally-bound names into account when calculating...

commite8d29a988f82b5a5c6fd2cc78ed6f1e8c3ce8a5e authorPhil Freeman <paf31@cantab.net> dateWed 15 Oct 2014, 08:42 (12 years ago) parentd9588ec02a7452
2 files changed+21−5
examples/passing/BindingGroups.purs+8 src/Language/PureScript/Sugar/BindingGroups.hs+13−5
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)
2626import Data.Maybe (isJust, mapMaybe)
2727import Control.Applicative ((<$>), (<*>), pure)
2828
29+import qualified Data.Set as S
30+
2931import Language.PureScript.Declarations
3032import Language.PureScript.Names
3133import Language.PureScript.Types
@@ -91,13 +93,19 @@ collapseBindingGroupsForValue other = other
9193
9294usedIdents :: ModuleName -> Declaration -> [Ident]
9395usedIdents moduleName =
94− let (f, _, _, _, _) = everythingOnValues (++) (const []) usedNames (const []) (const []) (const [])
96+ let (f, _, _, _, _) = everythingWithContextOnValues S.empty [] (++) def usedNamesE usedNamesB def def
9597 in nub . f
9698 where
97− usedNames :: Expr -> [Ident]
98− usedNames (Var (Qualified Nothing name)) = [name]
99− usedNames (Var (Qualified (Just moduleName') name)) | moduleName == moduleName' = [name]
100− usedNames _ = []
99+ def s _ = (s, [])
100+
101+ usedNamesE :: S.Set Ident -> Expr -> (S.Set Ident, [Ident])
102+ usedNamesE scope (Var (Qualified Nothing name)) | name `S.notMember` scope = (scope, [name])
103+ usedNamesE scope (Var (Qualified (Just moduleName') name)) | moduleName == moduleName' && name `S.notMember` scope = (scope, [name])
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), [])
101109
102110usedProperNames :: ModuleName -> Declaration -> [ProperName]
103111usedProperNames moduleName =