summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTibor Erdesz <erdeszt@gmail.com>2017-06-29 19:37:13 -0400
committerBen Gamari <ben@smart-cactus.org>2017-06-29 19:38:16 -0400
commit007f255644f885d445e47e291e50eb12b5ecd08d (patch)
tree2d6269ea631c17096d9aefdf8b2551f667e0faed
parent6171b0b326e52221a0631cf75eb4866b36abe631 (diff)
downloadhaskell-007f255644f885d445e47e291e50eb12b5ecd08d.tar.gz
Allow optional instance keyword in associated type family instances
Add the missing branch for parsing the optional 'instance' keyword in associated type family instance declarations. Fixes #13747 Reviewers: austin, bgamari Reviewed By: bgamari Subscribers: simonpj, RyanGlScott, rwbarton, thomie, mpickering Differential Revision: https://phabricator.haskell.org/D3673
-rw-r--r--compiler/parser/Parser.y34
-rw-r--r--docs/users_guide/8.4.1-notes.rst3
-rw-r--r--testsuite/tests/parser/should_compile/T13747.hs24
-rw-r--r--testsuite/tests/parser/should_compile/all.T1
4 files changed, 55 insertions, 7 deletions
diff --git a/compiler/parser/Parser.y b/compiler/parser/Parser.y
index 6e4b7740d5..603ac27cf4 100644
--- a/compiler/parser/Parser.y
+++ b/compiler/parser/Parser.y
@@ -1215,25 +1215,37 @@ opt_family :: { [AddAnn] }
: {- empty -} { [] }
| 'family' { [mj AnnFamily $1] }
+opt_instance :: { [AddAnn] }
+ : {- empty -} { [] }
+ | 'instance' { [mj AnnInstance $1] }
+
-- Associated type instances
--
at_decl_inst :: { LInstDecl GhcPs }
- -- type instance declarations
- : 'type' ty_fam_inst_eqn
+ -- type instance declarations, with optional 'instance' keyword
+ : 'type' opt_instance ty_fam_inst_eqn
-- Note the use of type for the head; this allows
-- infix type constructors and type patterns
- {% ams $2 (fst $ unLoc $2) >>
- amms (mkTyFamInst (comb2 $1 $2) (snd $ unLoc $2))
- (mj AnnType $1:(fst $ unLoc $2)) }
+ {% ams $3 (fst $ unLoc $3) >>
+ amms (mkTyFamInst (comb2 $1 $3) (snd $ unLoc $3))
+ (mj AnnType $1:$2++(fst $ unLoc $3)) }
- -- data/newtype instance declaration
+ -- data/newtype instance declaration, with optional 'instance' keyword
+ -- (can't use opt_instance because you get reduce/reduce errors)
| data_or_newtype capi_ctype tycl_hdr constrs maybe_derivings
{% amms (mkDataFamInst (comb4 $1 $3 $4 $5) (snd $ unLoc $1) $2 $3
Nothing (reverse (snd $ unLoc $4))
(fmap reverse $5))
((fst $ unLoc $1):(fst $ unLoc $4)) }
- -- GADT instance declaration
+ | data_or_newtype 'instance' capi_ctype tycl_hdr constrs maybe_derivings
+ {% amms (mkDataFamInst (comb4 $1 $4 $5 $6) (snd $ unLoc $1) $3 $4
+ Nothing (reverse (snd $ unLoc $5))
+ (fmap reverse $6))
+ ((fst $ unLoc $1):mj AnnInstance $2:(fst $ unLoc $5)) }
+
+ -- GADT instance declaration, with optional 'instance' keyword
+ -- (can't use opt_instance because you get reduce/reduce errors)
| data_or_newtype capi_ctype tycl_hdr opt_kind_sig
gadt_constrlist
maybe_derivings
@@ -1242,6 +1254,14 @@ at_decl_inst :: { LInstDecl GhcPs }
(fmap reverse $6))
((fst $ unLoc $1):(fst $ unLoc $4)++(fst $ unLoc $5)) }
+ | data_or_newtype 'instance' capi_ctype tycl_hdr opt_kind_sig
+ gadt_constrlist
+ maybe_derivings
+ {% amms (mkDataFamInst (comb4 $1 $4 $6 $7) (snd $ unLoc $1) $3
+ $4 (snd $ unLoc $5) (snd $ unLoc $6)
+ (fmap reverse $7))
+ ((fst $ unLoc $1):mj AnnInstance $2:(fst $ unLoc $5)++(fst $ unLoc $6)) }
+
data_or_newtype :: { Located (AddAnn, NewOrData) }
: 'data' { sL1 $1 (mj AnnData $1,DataType) }
| 'newtype' { sL1 $1 (mj AnnNewtype $1,NewType) }
diff --git a/docs/users_guide/8.4.1-notes.rst b/docs/users_guide/8.4.1-notes.rst
index f23cb360c9..7e918f22ce 100644
--- a/docs/users_guide/8.4.1-notes.rst
+++ b/docs/users_guide/8.4.1-notes.rst
@@ -80,6 +80,9 @@ Now we generate ::
used to build a GHC using compilers on your ``PATH`` instead of using the
bundled bindist. See :ghc-ticket:`13792`
+- The optional ``instance`` keyword is now usable in type family instance
+ declarations. See :ghc-ticket:`13747`
+
- Lots of other bugs. See `Trac <https://ghc.haskell.org/trac/ghc/query?status=closed&milestone=8.4.1&col=id&col=summary&col=status&col=type&col=priority&col=milestone&col=component&order=priority>`_
for a complete list.
diff --git a/testsuite/tests/parser/should_compile/T13747.hs b/testsuite/tests/parser/should_compile/T13747.hs
new file mode 100644
index 0000000000..749d8d2fc4
--- /dev/null
+++ b/testsuite/tests/parser/should_compile/T13747.hs
@@ -0,0 +1,24 @@
+{-# LANGUAGE TypeFamilies #-}
+{-# LANGUAGE GADTs #-}
+
+module T13747 where
+
+class C a where
+ type family TC a :: *
+
+class D a where
+ data family TD a :: *
+
+instance C Int where
+ type instance TC Int = Int
+
+instance D Double where
+ data instance TD Double = TDDouble
+
+instance D Int where
+ newtype instance TD Int = TDInt Int
+
+instance D Char where
+ data instance TD Char where
+ C1 :: TD Char
+ C2 :: TD Char
diff --git a/testsuite/tests/parser/should_compile/all.T b/testsuite/tests/parser/should_compile/all.T
index 2059979765..a9d6830701 100644
--- a/testsuite/tests/parser/should_compile/all.T
+++ b/testsuite/tests/parser/should_compile/all.T
@@ -107,3 +107,4 @@ test('T10582', expect_broken(10582), compile, [''])
test('DumpParsedAst', normal, compile, ['-dsuppress-uniques -ddump-parsed-ast'])
test('DumpRenamedAst', normal, compile, ['-dsuppress-uniques -ddump-rn-ast'])
test('DumpTypecheckedAst', normal, compile, ['-dsuppress-uniques -ddump-tc-ast'])
+test('T13747', normal, compile, [''])