diff options
| author | Matthew Pickering <matthewtpickering@gmail.com> | 2017-03-29 16:09:08 -0400 |
|---|---|---|
| committer | Ben Gamari <ben@smart-cactus.org> | 2017-03-29 16:44:43 -0400 |
| commit | 154d224ade3d9f22b0e22fc8be8f3907f1ad51d2 (patch) | |
| tree | 724891638c98c10d5e75f9195a23098ecdc82f9a | |
| parent | 04ea4c3f86db4e2cc7b2683f58f2076233039ebf (diff) | |
| download | haskell-154d224ade3d9f22b0e22fc8be8f3907f1ad51d2.tar.gz | |
Allow operators as record pattern synonym fields
Fixes #13454
Reviewers: austin, bgamari, dfeuer
Reviewed By: dfeuer
Subscribers: RyanGlScott, rwbarton, thomie
Differential Revision: https://phabricator.haskell.org/D3379
| -rw-r--r-- | compiler/parser/Parser.y | 4 | ||||
| -rw-r--r-- | testsuite/tests/patsyn/should_compile/T13454.hs | 15 | ||||
| -rw-r--r-- | testsuite/tests/patsyn/should_compile/all.T | 1 |
3 files changed, 18 insertions, 2 deletions
diff --git a/compiler/parser/Parser.y b/compiler/parser/Parser.y index caa22dc207..21f564e2b9 100644 --- a/compiler/parser/Parser.y +++ b/compiler/parser/Parser.y @@ -1362,8 +1362,8 @@ vars0 :: { [Located RdrName] } | varid vars0 { $1 : $2 } cvars1 :: { [RecordPatSynField (Located RdrName)] } - : varid { [RecordPatSynField $1 $1] } - | varid ',' cvars1 {% addAnnotation (getLoc $1) AnnComma (getLoc $2) >> + : var { [RecordPatSynField $1 $1] } + | var ',' cvars1 {% addAnnotation (getLoc $1) AnnComma (getLoc $2) >> return ((RecordPatSynField $1 $1) : $3 )} where_decls :: { Located ([AddAnn] diff --git a/testsuite/tests/patsyn/should_compile/T13454.hs b/testsuite/tests/patsyn/should_compile/T13454.hs new file mode 100644 index 0000000000..88a54419e9 --- /dev/null +++ b/testsuite/tests/patsyn/should_compile/T13454.hs @@ -0,0 +1,15 @@ +{-# LANGUAGE PatternSynonyms, ViewPatterns #-} +module T13454 where + +pattern MkOp :: Op -> Exp -> Exp -> Exp +pattern MkOp {(·), a, b} <- (splitOp -> Just ((·), a, b)) + where MkOp (·) a b = a · b + +data Exp = Val Int | Add Exp Exp | Mul Exp Exp deriving Show + +type Op = Exp -> Exp -> Exp + +splitOp :: Exp -> Maybe (Op, Exp, Exp) +splitOp (Add a b) = Just (Add, a, b) +splitOp (Mul a b) = Just (Mul, a, b) +splitOp _ = Nothing diff --git a/testsuite/tests/patsyn/should_compile/all.T b/testsuite/tests/patsyn/should_compile/all.T index 8fce7e987d..fa8a3d8455 100644 --- a/testsuite/tests/patsyn/should_compile/all.T +++ b/testsuite/tests/patsyn/should_compile/all.T @@ -67,3 +67,4 @@ test('T13349b', normal, compile, ['']) test('T13441', normal, compile, ['']) test('T13441a', normal, compile, ['']) test('T13441b', normal, compile_fail, ['']) +test('T13454', normal, compile, ['']) |
