Fixed error messages for RecursiveDo (#8501)
authorRupert Horlick <ruperthorlick@gmail.com>
Wed, 29 Mar 2017 19:26:11 +0000 (15:26 -0400)
committerBen Gamari <ben@smart-cactus.org>
Wed, 29 Mar 2017 20:07:52 +0000 (16:07 -0400)
Changes in a few different places to catch several different
types of error related to RecursiveDo

Signed-off-by: Rupert Horlick <ruperthorlick@gmail.com>
Test Plan: Three test cases, with further tests in comments

Reviewers: austin, bgamari

Reviewed By: bgamari

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D3271

15 files changed:
compiler/parser/Lexer.x
compiler/parser/RdrHsSyn.hs
compiler/rename/RnEnv.hs
compiler/utils/StringBuffer.hs
testsuite/tests/ghci/prog011/prog011.stderr
testsuite/tests/ghci/scripts/ghci014.stdout [deleted file]
testsuite/tests/mdo/should_fail/mdofail005.stderr
testsuite/tests/parser/should_fail/T8501a.hs [new file with mode: 0644]
testsuite/tests/parser/should_fail/T8501a.stderr [new file with mode: 0644]
testsuite/tests/parser/should_fail/T8501b.hs [new file with mode: 0644]
testsuite/tests/parser/should_fail/T8501b.stderr [new file with mode: 0644]
testsuite/tests/parser/should_fail/T8501c.hs [new file with mode: 0644]
testsuite/tests/parser/should_fail/T8501c.stderr [new file with mode: 0644]
testsuite/tests/parser/should_fail/all.T
testsuite/tests/parser/should_fail/readFail040.stderr

index a6e0a7b..4c86688 100644 (file)
@@ -2405,14 +2405,18 @@ srcParseErr options buf len
               $$ ppWhen (not th_enabled && token == "$") -- #7396
                         (text "Perhaps you intended to use TemplateHaskell")
               $$ ppWhen (token == "<-")
-                        (text "Perhaps this statement should be within a 'do' block?")
+                        (if mdoInLast100
+                           then text "Perhaps you intended to use RecursiveDo"
+                           else text "Perhaps this statement should be within a 'do' block?")
               $$ ppWhen (token == "=")
                         (text "Perhaps you need a 'let' in a 'do' block?"
                          $$ text "e.g. 'let x = 5' instead of 'x = 5'")
-              $$ ppWhen (not ps_enabled && pattern == "pattern") -- #12429
+              $$ ppWhen (not ps_enabled && pattern == "pattern ") -- #12429
                         (text "Perhaps you intended to use PatternSynonyms")
   where token = lexemeToString (offsetBytes (-len) buf) len
-        pattern = lexemeToString (offsetBytes (-len - 8) buf) 7
+        pattern = decodePrevNChars 8 buf
+        last100 = decodePrevNChars 100 buf
+        mdoInLast100 = "mdo" `isInfixOf` last100
         th_enabled = extopt LangExt.TemplateHaskell options
         ps_enabled = extopt LangExt.PatternSynonyms options
 
index e06c7e3..5b1006a 100644 (file)
@@ -805,8 +805,10 @@ checkLPat msg e@(L l _) = checkPat msg l e []
 
 checkPat :: SDoc -> SrcSpan -> LHsExpr RdrName -> [LPat RdrName]
          -> P (LPat RdrName)
-checkPat _ loc (L l (HsVar (L _ c))) args
+checkPat _ loc (L l e@(HsVar (L _ c))) args
   | isRdrDataCon c = return (L loc (ConPatIn (L l c) (PrefixCon args)))
+  | not (null args) && patIsRec c =
+      patFail (text "Perhaps you intended to use RecursiveDo") l e
 checkPat msg loc e args     -- OK to let this happen even if bang-patterns
                         -- are not enabled, because there is no valid
                         -- non-bang-pattern parse of (C ! e)
@@ -913,6 +915,9 @@ patFail msg loc e = parseErrorSDoc loc err
     where err = text "Parse error in pattern:" <+> ppr e
              $$ msg
 
+patIsRec :: RdrName -> Bool
+patIsRec e = e == mkUnqual varName (fsLit "rec")
+
 
 ---------------------------------------------------------------------------
 -- Check Equation Syntax
index 509e26e..7484061 100644 (file)
@@ -1856,7 +1856,8 @@ unknownNameSuggestions_ :: WhereLooking -> DynFlags
                        -> RdrName -> SDoc
 unknownNameSuggestions_ where_look dflags global_env local_env imports tried_rdr_name =
     similarNameSuggestions where_look dflags global_env local_env tried_rdr_name $$
-    importSuggestions where_look imports tried_rdr_name
+    importSuggestions where_look  imports tried_rdr_name $$
+    extensionSuggestions tried_rdr_name
 
 
 similarNameSuggestions :: WhereLooking -> DynFlags
@@ -2087,6 +2088,13 @@ importSuggestions where_look imports rdr_name
   (helpful_imports_hiding, helpful_imports_non_hiding)
     = partition (imv_is_hiding . snd) helpful_imports
 
+extensionSuggestions :: RdrName -> SDoc
+extensionSuggestions rdrName
+  | rdrName == mkUnqual varName (fsLit "mdo") ||
+    rdrName == mkUnqual varName (fsLit "rec")
+      = text "Perhaps you meant to use RecursiveDo"
+  | otherwise = Outputable.empty
+
 {-
 ************************************************************************
 *                                                                      *
index bac752a..ec5184a 100644 (file)
@@ -36,6 +36,7 @@ module StringBuffer
         -- * Conversion
         lexemeToString,
         lexemeToFastString,
+        decodePrevNChars,
 
          -- * Parsing integers
         parseUnsignedInteger,
@@ -263,6 +264,20 @@ lexemeToFastString (StringBuffer buf _ cur) len =
      withForeignPtr buf $ \ptr ->
        return $! mkFastStringBytes (ptr `plusPtr` cur) len
 
+-- | Return the previous @n@ characters (or fewer if we are less than @n@
+-- characters into the buffer.
+decodePrevNChars :: Int -> StringBuffer -> String
+decodePrevNChars n (StringBuffer buf _ cur) =
+    inlinePerformIO $ withForeignPtr buf $ \p0 ->
+      go p0 n "" (p0 `plusPtr` (cur - 1))
+  where
+    go :: Ptr Word8 -> Int -> String -> Ptr Word8 -> IO String
+    go buf0 n acc p | n == 0 || buf0 >= p = return acc
+    go buf0 n acc p = do
+        p' <- utf8PrevChar p
+        let (c,_) = utf8DecodeChar p'
+        go buf0 (n - 1) (c:acc) p'
+
 -- -----------------------------------------------------------------------------
 -- Parsing integer strings in various bases
 parseUnsignedInteger :: StringBuffer -> Int -> Integer -> (Char->Int) -> Integer
index 6ee1fac..68c310d 100644 (file)
@@ -1,2 +1,2 @@
 
-prog011.hx:14:22: Empty 'do' block
+prog011.hx:14:22: error: Empty 'do' block
diff --git a/testsuite/tests/ghci/scripts/ghci014.stdout b/testsuite/tests/ghci/scripts/ghci014.stdout
deleted file mode 100644 (file)
index 324972d..0000000
+++ /dev/null
@@ -1,982 +0,0 @@
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
-                     test : *                                (0)
index 594fea2..0ebead1 100644 (file)
@@ -1,4 +1,4 @@
 
-mdofail005.hs:11:14:
+mdofail005.hs:11:14: error:
     parse error on input ‘<-’
-    Perhaps this statement should be within a 'do' block?
+    Perhaps you intended to use RecursiveDo
diff --git a/testsuite/tests/parser/should_fail/T8501a.hs b/testsuite/tests/parser/should_fail/T8501a.hs
new file mode 100644 (file)
index 0000000..e8b0641
--- /dev/null
@@ -0,0 +1,27 @@
+module Test where
+
+foo :: IO ()
+foo = do
+  rec str <- return "foo"
+  putStrLn str
+
+-- Should fail
+-- foo' :: IO ()
+-- foo' = do
+--   rec {str <- return "foo" ;
+--   putStrLn str}
+--   return ()
+
+-- Should fail
+-- foo'' :: IO ()
+-- foo'' = do
+--   rec putStrLn "test"
+--   str <- return "foo"
+--   putStrLn str
+--   return ()
+
+-- Should compile
+-- foo'''' :: IO ()
+-- foo'''' = do
+--   rec <- return "foo"
+--   putStrLn "test"
diff --git a/testsuite/tests/parser/should_fail/T8501a.stderr b/testsuite/tests/parser/should_fail/T8501a.stderr
new file mode 100644 (file)
index 0000000..d85dfc2
--- /dev/null
@@ -0,0 +1,4 @@
+
+T8501a.hs:5:3: error:
+    Parse error in pattern: rec
+    Perhaps you intended to use RecursiveDo
diff --git a/testsuite/tests/parser/should_fail/T8501b.hs b/testsuite/tests/parser/should_fail/T8501b.hs
new file mode 100644 (file)
index 0000000..3973ccb
--- /dev/null
@@ -0,0 +1,10 @@
+module Test where
+
+bar :: IO ()
+bar = mdo
+    str <- return "bar"
+    putStrLn str
+
+-- Should fail
+-- bar' :: IO ()
+-- bar' = mdo {str <- return "bar" ; putStrLn str}
diff --git a/testsuite/tests/parser/should_fail/T8501b.stderr b/testsuite/tests/parser/should_fail/T8501b.stderr
new file mode 100644 (file)
index 0000000..e9e4b5e
--- /dev/null
@@ -0,0 +1,4 @@
+
+T8501b.hs:5:9: error:
+    parse error on input ‘<-’
+    Perhaps you intended to use RecursiveDo
diff --git a/testsuite/tests/parser/should_fail/T8501c.hs b/testsuite/tests/parser/should_fail/T8501c.hs
new file mode 100644 (file)
index 0000000..8dea956
--- /dev/null
@@ -0,0 +1,15 @@
+module Test where
+
+baz :: IO ()
+baz = mdo
+    putStrLn "baz"
+
+-- Should fail
+-- baz' :: IO ()
+-- baz' = mdo
+--     putStrLn "baz"
+--     str <- return "test"
+
+-- Should fail (and needs better error)
+-- baz' :: IO ()
+-- baz' = mdo {putStrLn "baz"}
diff --git a/testsuite/tests/parser/should_fail/T8501c.stderr b/testsuite/tests/parser/should_fail/T8501c.stderr
new file mode 100644 (file)
index 0000000..b12b53e
--- /dev/null
@@ -0,0 +1,6 @@
+
+T8501c.hs:4:7: error:
+    • Variable not in scope:
+        mdo :: (String -> IO ()) -> [Char] -> IO ()
+    • Perhaps you meant ‘mod’ (imported from Prelude)
+      Perhaps you meant to use RecursiveDo
index b897484..883e0b2 100644 (file)
@@ -98,3 +98,6 @@ test('T12429', normal, compile_fail, [''])
 test('T12811', normal, compile_fail, [''])
 test('T13260', normal, compile_fail, [''])
 test('T13414', literate, compile_fail, [''])
+test('T8501a', normal, compile_fail, [''])
+test('T8501b', normal, compile_fail, [''])
+test('T8501c', normal, compile_fail, [''])
index 728090b..663220d 100644 (file)
@@ -1,4 +1,4 @@
 
-readFail040.hs:7:11:
+readFail040.hs:7:11: error:
     parse error on input ‘<-’
-    Perhaps this statement should be within a 'do' block?
+    Perhaps you intended to use RecursiveDo