git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Fix an issue with type decls in instances
62c2164Phil Freeman
examples/passing/LetInInstance.pursnew file+12
@@ -0,0 +1,12 @@
1+module Main where
2+
3+class Foo a where
4+ foo :: a -> String
5+
6+instance fooString :: Foo String where
7+ foo = go
8+ where
9+ go :: String -> String
10+ go s = s
11+
12+main = Debug.Trace.trace "Done"
src/Language/PureScript/Sugar/Names.hs+6−5
@@ -17,7 +17,7 @@ module Language.PureScript.Sugar.Names (
17) where
17) where
18
18
19import Data.Data
19import Data.Data
20−import Data.Maybe (fromMaybe, isJust)
20+import Data.Maybe (fromMaybe, isJust, mapMaybe)
21import Data.Generics (extM, mkM, everywhereM)
21import Data.Generics (extM, mkM, everywhereM)
22import Data.Generics.Extras (mkS, extS, everywhereWithContextM')
22import Data.Generics.Extras (mkS, extS, everywhereWithContextM')
23
23
@@ -200,7 +200,7 @@ renameInModule imports exports (Module mn decls exps) =
200 rethrowFor "declaration" name $ ValueDeclaration name nameKind [] Nothing <$> updateAll val'
200 rethrowFor "declaration" name $ ValueDeclaration name nameKind [] Nothing <$> updateAll val'
201 where
201 where
202 bindFunctionArgs bound (Abs (Left arg) val') = return (arg : bound, Abs (Left arg) val')
202 bindFunctionArgs bound (Abs (Left arg) val') = return (arg : bound, Abs (Left arg) val')
203− bindFunctionArgs bound (Let ds val') = let args = map letBoundVariable ds in
203+ bindFunctionArgs bound (Let ds val') = let args = mapMaybe letBoundVariable ds in
204 return (args ++ bound, Let ds val')
204 return (args ++ bound, Let ds val')
205 bindFunctionArgs bound (Var name'@(Qualified Nothing ident)) | ident `notElem` bound =
205 bindFunctionArgs bound (Var name'@(Qualified Nothing ident)) | ident `notElem` bound =
206 (,) bound <$> (Var <$> updateValueName name')
206 (,) bound <$> (Var <$> updateValueName name')
@@ -214,10 +214,10 @@ renameInModule imports exports (Module mn decls exps) =
214 bindBinders :: [Ident] -> CaseAlternative -> Either String ([Ident], CaseAlternative)
214 bindBinders :: [Ident] -> CaseAlternative -> Either String ([Ident], CaseAlternative)
215 bindBinders bound c@(CaseAlternative bs _ _) = return (binderNames bs ++ bound, c)
215 bindBinders bound c@(CaseAlternative bs _ _) = return (binderNames bs ++ bound, c)
216
216
217− letBoundVariable :: Declaration -> Ident
217+ letBoundVariable :: Declaration -> Maybe Ident
218− letBoundVariable (ValueDeclaration ident _ _ _ _) = ident
218+ letBoundVariable (ValueDeclaration ident _ _ _ _) = Just ident
219 letBoundVariable (PositionedDeclaration _ d) = letBoundVariable d
219 letBoundVariable (PositionedDeclaration _ d) = letBoundVariable d
220− letBoundVariable _ = error "Invalid argument to letBoundVariable"
220+ letBoundVariable _ = Nothing
221 go (ValueDeclaration name _ _ _ _) = error $ "Binders should have been desugared in " ++ show name
221 go (ValueDeclaration name _ _ _ _) = error $ "Binders should have been desugared in " ++ show name
222 go (ExternDeclaration fit name js ty) =
222 go (ExternDeclaration fit name js ty) =
223 rethrowFor "declaration" name $ ExternDeclaration <$> pure fit <*> pure name <*> pure js <*> updateType' ty
223 rethrowFor "declaration" name $ ExternDeclaration <$> pure fit <*> pure name <*> pure js <*> updateType' ty
@@ -449,3 +449,4 @@ resolveImport currentModule importModule exps imps impQual = maybe importAll (fo
449 then return item
449 then return item
450 else throwError $ "Unable to find " ++ t ++ " '" ++ show (Qualified (Just importModule) item) ++ "'"
450 else throwError $ "Unable to find " ++ t ++ " '" ++ show (Qualified (Just importModule) item) ++ "'"
451
451
452+