[commit: ghc] master: Treat duplicate pattern synonym signatures as an error (2a3af15)

git at git.haskell.org git at git.haskell.org
Mon Jul 4 21:31:34 UTC 2016


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

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/2a3af15270d1c04745b1c42e61bf4d5f6dbc8ad5/ghc

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

commit 2a3af15270d1c04745b1c42e61bf4d5f6dbc8ad5
Author: Seraphime Kirkovski <kirkseraph at gmail.com>
Date:   Fri Jul 1 14:30:10 2016 +0200

    Treat duplicate pattern synonym signatures as an error
    
    Fixes issue T12165 by banning duplicate pattern synonyms
    signatures. This seems to me the best solution because:
    
       1) it is coherent with the way we treat other duplicate signatures
    
       2) the typechecker currently doesn't try to apply a second
           signature to a pattern to see if it matches, probably because
           it assumes there is no more than one signature per object.
    
    Test Plan: ./validate
    
    Reviewers: goldfire, austin, mpickering, bgamari
    
    Reviewed By: mpickering, bgamari
    
    Subscribers: mpickering, thomie
    
    Differential Revision: https://phabricator.haskell.org/D2361
    
    GHC Trac Issues: #12165


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

2a3af15270d1c04745b1c42e61bf4d5f6dbc8ad5
 compiler/rename/RnBinds.hs                       | 2 ++
 testsuite/tests/patsyn/should_fail/T12165.hs     | 6 ++++++
 testsuite/tests/patsyn/should_fail/T12165.stderr | 5 +++++
 testsuite/tests/patsyn/should_fail/all.T         | 1 +
 4 files changed, 14 insertions(+)

diff --git a/compiler/rename/RnBinds.hs b/compiler/rename/RnBinds.hs
index f6c18b4..2e4f4db 100644
--- a/compiler/rename/RnBinds.hs
+++ b/compiler/rename/RnBinds.hs
@@ -988,6 +988,7 @@ findDupSigs sigs
     expand_sig sig@(InlineSig n _)           = [(n,sig)]
     expand_sig sig@(TypeSig ns _)            = [(n,sig) | n <- ns]
     expand_sig sig@(ClassOpSig _ ns _)       = [(n,sig) | n <- ns]
+    expand_sig sig@(PatSynSig ns  _ )        = [(n,sig) | n <- ns]
     expand_sig _ = []
 
     matching_sig (L _ n1,sig1) (L _ n2,sig2)       = n1 == n2 && mtch sig1 sig2
@@ -995,6 +996,7 @@ findDupSigs sigs
     mtch (InlineSig {})        (InlineSig {})      = True
     mtch (TypeSig {})          (TypeSig {})        = True
     mtch (ClassOpSig d1 _ _)   (ClassOpSig d2 _ _) = d1 == d2
+    mtch (PatSynSig _ _)       (PatSynSig _ _)     = True
     mtch _ _ = False
 
 -- Warn about multiple MINIMAL signatures
diff --git a/testsuite/tests/patsyn/should_fail/T12165.hs b/testsuite/tests/patsyn/should_fail/T12165.hs
new file mode 100644
index 0000000..0fbf964
--- /dev/null
+++ b/testsuite/tests/patsyn/should_fail/T12165.hs
@@ -0,0 +1,6 @@
+{-# LANGUAGE PatternSynonyms #-}
+module ShouldFail where
+
+pattern P :: a -> b -> Maybe (a,b)
+pattern P :: foo => bar => blah -> urgh
+pattern P x y = Just (x, y)
diff --git a/testsuite/tests/patsyn/should_fail/T12165.stderr b/testsuite/tests/patsyn/should_fail/T12165.stderr
new file mode 100644
index 0000000..881e469
--- /dev/null
+++ b/testsuite/tests/patsyn/should_fail/T12165.stderr
@@ -0,0 +1,5 @@
+
+T12165.hs:5:9: error:
+    Duplicate pattern synonym signatures for ā€˜Pā€™
+    at T12165.hs:4:9
+       T12165.hs:5:9
diff --git a/testsuite/tests/patsyn/should_fail/all.T b/testsuite/tests/patsyn/should_fail/all.T
index 658a5c0..fe0922c 100644
--- a/testsuite/tests/patsyn/should_fail/all.T
+++ b/testsuite/tests/patsyn/should_fail/all.T
@@ -31,3 +31,4 @@ test('T11053', normal, compile, ['-fwarn-missing-pattern-synonym-signatures'])
 test('T10426', normal, compile_fail, [''])
 test('T11265', normal, compile_fail, [''])
 test('T11667', normal, compile_fail, [''])
+test('T12165', normal, compile_fail, [''])



More information about the ghc-commits mailing list