Disallow empty where bindings in pattern synonym declarations.
authorMatthew Pickering <matthewtpickering@gmail.com>
Sun, 20 Dec 2015 23:45:28 +0000 (23:45 +0000)
committerMatthew Pickering <matthewtpickering@gmail.com>
Sun, 20 Dec 2015 23:46:18 +0000 (23:46 +0000)
Reviewers: austin, bgamari

Reviewed By: bgamari

Subscribers: thomie

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

GHC Trac Issues: #10426

compiler/parser/RdrHsSyn.hs
testsuite/tests/patsyn/should_compile/all.T
testsuite/tests/patsyn/should_fail/T10426.hs [moved from testsuite/tests/patsyn/should_compile/T10426.hs with 100% similarity]
testsuite/tests/patsyn/should_fail/T10426.stderr [new file with mode: 0644]
testsuite/tests/patsyn/should_fail/all.T

index cc8a8ec..7e61172 100644 (file)
@@ -465,8 +465,9 @@ recordPatSynErr loc pat =
 mkPatSynMatchGroup :: Located RdrName
                    -> Located (OrdList (LHsDecl RdrName))
                    -> P (MatchGroup RdrName (LHsExpr RdrName))
-mkPatSynMatchGroup (L _ patsyn_name) (L _ decls) =
+mkPatSynMatchGroup (L loc patsyn_name) (L _ decls) =
     do { matches <- mapM fromDecl (fromOL decls)
+       ; when (length matches /= 1) (wrongNumberErr loc)
        ; return $ mkMatchGroup FromSource matches }
   where
     fromDecl (L loc decl@(ValD (PatBind pat@(L _ (ConPatIn (L _ name) details)) rhs _ _ _))) =
@@ -490,6 +491,11 @@ mkPatSynMatchGroup (L _ patsyn_name) (L _ decls) =
         text "pattern synonym 'where' clause must bind the pattern synonym's name" <+>
         quotes (ppr patsyn_name) $$ ppr decl
 
+    wrongNumberErr loc =
+      parseErrorSDoc loc $
+      text "pattern synonym 'where' clause can not be empty." $$
+      text "In the pattern synonym declaration for: " <+> ppr (patsyn_name)
+
 mkConDeclH98 :: Located RdrName -> Maybe [LHsTyVarBndr RdrName]
                 -> LHsContext RdrName -> HsConDeclDetails RdrName
                 -> ConDecl RdrName
index 4452711..7ab5ac7 100644 (file)
@@ -24,7 +24,6 @@ test('T9889', normal, compile, [''])
 test('T9867', normal, compile, [''])
 test('T9975a', normal, compile_fail, [''])
 test('T9975b', normal, compile, [''])
-test('T10426', [expect_broken(10426)], compile, [''])
 test('T10747', normal, compile, [''])
 test('T10997', [extra_clean(['T10997a.hi', 'T10997a.o'])], multimod_compile, ['T10997', '-v0'])
 test('T10997_1', [extra_clean(['T10997_1a.hi', 'T10997_1a.o'])], multimod_compile, ['T10997_1', '-v0'])
diff --git a/testsuite/tests/patsyn/should_fail/T10426.stderr b/testsuite/tests/patsyn/should_fail/T10426.stderr
new file mode 100644 (file)
index 0000000..9b03e11
--- /dev/null
@@ -0,0 +1,4 @@
+
+T10426.hs:3:9: error:
+    pattern synonym 'where' clause can not be empty.
+    In the pattern synonym declaration for:  Id
index 26c68ca..6ef64ae 100644 (file)
@@ -26,3 +26,4 @@ test('export-super-class-fail', expect_broken(10653), compile_fail, [''])
 test('export-type-synonym', normal, compile_fail, [''])
 test('export-ps-rec-sel', normal, compile_fail, [''])
 test('T11053', normal, compile, ['-fwarn-missing-pat-syn-sigs'])
+test('T10426', normal, compile_fail, [''])