@@ -9,7 +9,6 @@ import Prelude.Compat
9import Control.Monad.Error.Class (MonadError(..))
9import Control.Monad.Error.Class (MonadError(..))
10import Control.Monad.Supply.Class
10import Control.Monad.Supply.Class
13import Language.PureScript.AST
12import Language.PureScript.AST
14import Language.PureScript.Crash
13import Language.PureScript.Crash
15import Language.PureScript.Errors
14import Language.PureScript.Errors
@@ -49,6 +48,8 @@ desugarDo d =
49 return $ App (App bind val) (Abs (Left (Ident C.__unused)) rest')
48 return $ App (App bind val) (Abs (Left (Ident C.__unused)) rest')
50 go [DoNotationBind _ _] = throwError . errorMessage $ InvalidDoBind
49 go [DoNotationBind _ _] = throwError . errorMessage $ InvalidDoBind
51 go (DoNotationBind NullBinder val : rest) = go (DoNotationValue val : rest)
50 go (DoNotationBind NullBinder val : rest) = go (DoNotationValue val : rest)
51+ go (DoNotationBind b _ : _) | Ident C.bind `elem` binderNames b =
52+ throwError . errorMessage $ CannotUseBindWithDo
52 go (DoNotationBind (VarBinder ident) val : rest) = do
53 go (DoNotationBind (VarBinder ident) val : rest) = do
53 rest' <- go rest
54 rest' <- go rest
54 return $ App (App bind val) (Abs (Left ident) rest')
55 return $ App (App bind val) (Abs (Left ident) rest')
@@ -58,6 +59,12 @@ desugarDo d =
58 return $ App (App bind val) (Abs (Left ident) (Case [Var (Qualified Nothing ident)] [CaseAlternative [binder] (Right rest')]))
59 return $ App (App bind val) (Abs (Left ident) (Case [Var (Qualified Nothing ident)] [CaseAlternative [binder] (Right rest')]))
59 go [DoNotationLet _] = throwError . errorMessage $ InvalidDoLet
60 go [DoNotationLet _] = throwError . errorMessage $ InvalidDoLet
60 go (DoNotationLet ds : rest) = do
61 go (DoNotationLet ds : rest) = do
62+ let checkBind :: Declaration -> m ()
63+ checkBind (ValueDeclaration (Ident name) _ _ _)
64+ | name == C.bind = throwError . errorMessage $ CannotUseBindWithDo
65+ checkBind (PositionedDeclaration pos _ decl) = rethrowWithPosition pos (checkBind decl)
66+ checkBind _ = pure ()
61 rest' <- go rest
68 rest' <- go rest
62 return $ Let ds rest'
69 return $ Let ds rest'
63 go (PositionedDoNotationElement pos com el : rest) = rethrowWithPosition pos $ PositionedValue pos com <$> go (el : rest)
70 go (PositionedDoNotationElement pos com el : rest) = rethrowWithPosition pos $ PositionedValue pos com <$> go (el : rest)