Allow pattern synonyms which have several clauses.
authorMatthew Pickering <matthewtpickering@gmail.com>
Fri, 15 Jan 2016 16:40:51 +0000 (17:40 +0100)
committerBen Gamari <ben@smart-cactus.org>
Fri, 15 Jan 2016 16:40:53 +0000 (17:40 +0100)
But still disallow empty pattern synonym builder declarations. Handling
this incorrectly was the cause of #11367.

Test Plan: ./validate

Reviewers: austin, bgamari

Reviewed By: bgamari

Subscribers: thomie

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

GHC Trac Issues: #11367

compiler/parser/RdrHsSyn.hs
testsuite/tests/patsyn/should_compile/T11367.hs [new file with mode: 0644]
testsuite/tests/patsyn/should_compile/all.T

index 74a18f1..ada9bf2 100644 (file)
@@ -464,7 +464,7 @@ mkPatSynMatchGroup :: Located RdrName
                    -> P (MatchGroup RdrName (LHsExpr RdrName))
 mkPatSynMatchGroup (L loc patsyn_name) (L _ decls) =
     do { matches <- mapM fromDecl (fromOL decls)
-       ; when (length matches /= 1) (wrongNumberErr loc)
+       ; when (null matches) (wrongNumberErr loc)
        ; return $ mkMatchGroup FromSource matches }
   where
     fromDecl (L loc decl@(ValD (PatBind pat@(L _ (ConPatIn ln@(L _ name) details)) rhs _ _ _))) =
diff --git a/testsuite/tests/patsyn/should_compile/T11367.hs b/testsuite/tests/patsyn/should_compile/T11367.hs
new file mode 100644 (file)
index 0000000..8e00a50
--- /dev/null
@@ -0,0 +1,7 @@
+{-# LANGUAGE PatternSynonyms, ViewPatterns #-}
+module T11367 where
+
+pattern A :: Int -> String
+pattern A n <- (read -> n) where
+        A 0 = "hi"
+        A 1 = "bye"
index 5205a24..14940f2 100644 (file)
@@ -48,3 +48,4 @@ test('T11224b', normal, compile, [''])
 test('MoreEx', normal, compile, [''])
 test('T11283', normal, compile, [''])
 test('T11336', normal, compile, [''])
+test('T11367', normal, compile, [''])