[commit: ghc] ghc-8.0: Allow pattern synonyms which have several clauses. (e2c7397)

git at git.haskell.org git at git.haskell.org
Sat Jan 16 12:49:16 UTC 2016


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

On branch  : ghc-8.0
Link       : http://ghc.haskell.org/trac/ghc/changeset/e2c739772bfd12f1ad0bd900abbb34bc28de543e/ghc

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

commit e2c739772bfd12f1ad0bd900abbb34bc28de543e
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
    
    (cherry picked from commit 443bf04485f997be2e3a744102605645c54e9d61)


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

e2c739772bfd12f1ad0bd900abbb34bc28de543e
 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 1094f49..25e5de1 100644
--- a/compiler/parser/RdrHsSyn.hs
+++ b/compiler/parser/RdrHsSyn.hs
@@ -468,7 +468,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 880d6b2..ebfca5f 100644
--- a/testsuite/tests/patsyn/should_compile/all.T
+++ b/testsuite/tests/patsyn/should_compile/all.T
@@ -47,3 +47,4 @@ test('T10897', normal, multi_compile, ['T10897', [
 test('T11224b', normal, compile, [''])
 test('MoreEx', normal, compile, [''])
 test('T11283', normal, compile, [''])
+test('T11367', normal, compile, [''])



More information about the ghc-commits mailing list