@@ -9,7 +9,6 @@ import Prelude.Compat
99import Control.Monad.Error.Class (MonadError(..))
1010import Control.Monad.Supply.Class
1111
12−
1312import Language.PureScript.AST
1413import Language.PureScript.Crash
1514import Language.PureScript.Errors
@@ -49,6 +48,8 @@ desugarDo d =
4948 return $ App (App bind val) (Abs (Left (Ident C.__unused)) rest')
5049 go [DoNotationBind _ _] = throwError . errorMessage $ InvalidDoBind
5150 go (DoNotationBind NullBinder val : rest) = go (DoNotationValue val : rest)
51+ go (DoNotationBind b _ : _) | Ident C.bind `elem` binderNames b =
52+ throwError . errorMessage $ CannotUseBindWithDo
5253 go (DoNotationBind (VarBinder ident) val : rest) = do
5354 rest' <- go rest
5455 return $ App (App bind val) (Abs (Left ident) rest')
@@ -58,6 +59,12 @@ desugarDo d =
5859 return $ App (App bind val) (Abs (Left ident) (Case [Var (Qualified Nothing ident)] [CaseAlternative [binder] (Right rest')]))
5960 go [DoNotationLet _] = throwError . errorMessage $ InvalidDoLet
6061 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 ()
67+ mapM_ checkBind ds
6168 rest' <- go rest
6269 return $ Let ds rest'
6370 go (PositionedDoNotationElement pos com el : rest) = rethrowWithPosition pos $ PositionedValue pos com <$> go (el : rest)