[commit: ghc] master: Allow pattern synonyms which have several clauses. (443bf04)

git at git.haskell.org git at git.haskell.org
Fri Jan 15 17:15:42 UTC 2016


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/443bf04485f997be2e3a744102605645c54e9d61/ghc

>---------------------------------------------------------------

commit 443bf04485f997be2e3a744102605645c54e9d61
Author: Matthew Pickering <matthewtpickering at gmail.com>
Date:   Fri Jan 15 17:40:51 2016 +0100

    Allow pattern synonyms which have several clauses.
    
    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


>---------------------------------------------------------------

443bf04485f997be2e3a744102605645c54e9d61
 compiler/parser/RdrHsSyn.hs                     | 2 +-
 testsuite/tests/patsyn/should_compile/T11367.hs | 7 +++++++
 testsuite/tests/patsyn/should_compile/all.T     | 1 +
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/compiler/parser/RdrHsSyn.hs b/compiler/parser/RdrHsSyn.hs
index 74a18f1..ada9bf2 100644
--- a/compiler/parser/RdrHsSyn.hs
+++ b/compiler/parser/RdrHsSyn.hs
@@ -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
index 0000000..8e00a50
--- /dev/null
+++ b/testsuite/tests/patsyn/should_compile/T11367.hs
@@ -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"
diff --git a/testsuite/tests/patsyn/should_compile/all.T b/testsuite/tests/patsyn/should_compile/all.T
index 5205a24..14940f2 100644
--- a/testsuite/tests/patsyn/should_compile/all.T
+++ b/testsuite/tests/patsyn/should_compile/all.T
@@ -48,3 +48,4 @@ test('T11224b', normal, compile, [''])
 test('MoreEx', normal, compile, [''])
 test('T11283', normal, compile, [''])
 test('T11336', normal, compile, [''])
+test('T11367', normal, compile, [''])



More information about the ghc-commits mailing list