From 154d224ade3d9f22b0e22fc8be8f3907f1ad51d2 Mon Sep 17 00:00:00 2001 From: Matthew Pickering Date: Wed, 29 Mar 2017 16:09:08 -0400 Subject: 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 --- compiler/parser/Parser.y | 4 ++-- testsuite/tests/patsyn/should_compile/T13454.hs | 15 +++++++++++++++ testsuite/tests/patsyn/should_compile/all.T | 1 + 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 testsuite/tests/patsyn/should_compile/T13454.hs 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, ['']) -- cgit v1.2.1