git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #604 from purescript/533
205651cPhil Freeman
examples/failing/OverlappingArguments.pursnew file+3
@@ -0,0 +1,3 @@
1+module OverlappingArguments where
2+
3+f x x = x
examples/failing/OverlappingBinders.pursnew file+4
@@ -0,0 +1,4 @@
1+module OverlappingBinders where
2+
3+f x = case x of
4+ (y:y@(z:zs)) -> y
src/Language/PureScript/Sugar/CaseDeclarations.hs+3−1
@@ -20,7 +20,7 @@ module Language.PureScript.Sugar.CaseDeclarations (
20) where
20) where
21
21
22import Data.Monoid ((<>))
22import Data.Monoid ((<>))
23−import Data.List (groupBy)
23+import Data.List (nub, groupBy)
24
24
25import Control.Applicative
25import Control.Applicative
26import Control.Monad ((<=<), forM, join, unless, replicateM)
26import Control.Monad ((<=<), forM, join, unless, replicateM)
@@ -31,6 +31,7 @@ import Language.PureScript.Declarations
31import Language.PureScript.Environment
31import Language.PureScript.Environment
32import Language.PureScript.Errors
32import Language.PureScript.Errors
33import Language.PureScript.Supply
33import Language.PureScript.Supply
34+import Language.PureScript.TypeChecker.Monad (guardWith)
34
35
35-- |
36-- |
36-- Replace all top-level binders in a module with case expressions.
37-- Replace all top-level binders in a module with case expressions.
@@ -82,6 +83,7 @@ toDecls :: [Declaration] -> SupplyT (Either ErrorStack) [Declaration]
82toDecls [ValueDeclaration ident nameKind bs Nothing val] | all isVarBinder bs = do
83toDecls [ValueDeclaration ident nameKind bs Nothing val] | all isVarBinder bs = do
83 let args = map (\(VarBinder arg) -> arg) bs
84 let args = map (\(VarBinder arg) -> arg) bs
84 body = foldr (Abs . Left) val args
85 body = foldr (Abs . Left) val args
86+ guardWith (strMsg "Overlapping function argument names") $ length (nub args) == length args
85 return [ValueDeclaration ident nameKind [] Nothing body]
87 return [ValueDeclaration ident nameKind [] Nothing body]
86toDecls ds@(ValueDeclaration ident _ bs _ _ : _) = do
88toDecls ds@(ValueDeclaration ident _ bs _ _ : _) = do
87 let tuples = map toTuple ds
89 let tuples = map toTuple ds
src/Language/PureScript/TypeChecker/Types.hs+2
@@ -785,6 +785,8 @@ inferBinder val (PositionedBinder pos binder) =
785checkBinders :: [Type] -> Type -> [CaseAlternative] -> UnifyT Type Check [CaseAlternative]
785checkBinders :: [Type] -> Type -> [CaseAlternative] -> UnifyT Type Check [CaseAlternative]
786checkBinders _ _ [] = return []
786checkBinders _ _ [] = return []
787checkBinders nvals ret (CaseAlternative binders grd val : bs) = do
787checkBinders nvals ret (CaseAlternative binders grd val : bs) = do
788+ guardWith (strMsg "Overlapping binders in case statement") $
789+ let ns = concatMap binderNames binders in length (nub ns) == length ns
788 Just moduleName <- checkCurrentModule <$> get
790 Just moduleName <- checkCurrentModule <$> get
789 m1 <- M.unions <$> zipWithM inferBinder nvals binders
791 m1 <- M.unions <$> zipWithM inferBinder nvals binders
790 r <- bindLocalVariables moduleName [ (name, ty, Defined) | (name, ty) <- M.toList m1 ] $ do
792 r <- bindLocalVariables moduleName [ (name, ty, Defined) | (name, ty) <- M.toList m1 ] $ do