Commit 007f2556 authored by erdeszt's avatar erdeszt Committed by Ben Gamari

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
parent 6171b0b3
......@@ -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) }
......
......@@ -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.
......
{-# 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
......@@ -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, [''])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment