Commit 8d954125 authored by Matthew Pickering's avatar Matthew Pickering

Disallow empty where bindings in pattern synonym declarations.

Reviewers: austin, bgamari

Reviewed By: bgamari

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D1665

GHC Trac Issues: #10426
parent 1a86413e
...@@ -465,8 +465,9 @@ recordPatSynErr loc pat = ...@@ -465,8 +465,9 @@ recordPatSynErr loc pat =
mkPatSynMatchGroup :: Located RdrName mkPatSynMatchGroup :: Located RdrName
-> Located (OrdList (LHsDecl RdrName)) -> Located (OrdList (LHsDecl RdrName))
-> P (MatchGroup RdrName (LHsExpr RdrName)) -> P (MatchGroup RdrName (LHsExpr RdrName))
mkPatSynMatchGroup (L _ patsyn_name) (L _ decls) = mkPatSynMatchGroup (L loc patsyn_name) (L _ decls) =
do { matches <- mapM fromDecl (fromOL decls) do { matches <- mapM fromDecl (fromOL decls)
; when (length matches /= 1) (wrongNumberErr loc)
; return $ mkMatchGroup FromSource matches } ; return $ mkMatchGroup FromSource matches }
where where
fromDecl (L loc decl@(ValD (PatBind pat@(L _ (ConPatIn (L _ name) details)) rhs _ _ _))) = fromDecl (L loc decl@(ValD (PatBind pat@(L _ (ConPatIn (L _ name) details)) rhs _ _ _))) =
...@@ -490,6 +491,11 @@ mkPatSynMatchGroup (L _ patsyn_name) (L _ decls) = ...@@ -490,6 +491,11 @@ mkPatSynMatchGroup (L _ patsyn_name) (L _ decls) =
text "pattern synonym 'where' clause must bind the pattern synonym's name" <+> text "pattern synonym 'where' clause must bind the pattern synonym's name" <+>
quotes (ppr patsyn_name) $$ ppr decl quotes (ppr patsyn_name) $$ ppr decl
wrongNumberErr loc =
parseErrorSDoc loc $
text "pattern synonym 'where' clause can not be empty." $$
text "In the pattern synonym declaration for: " <+> ppr (patsyn_name)
mkConDeclH98 :: Located RdrName -> Maybe [LHsTyVarBndr RdrName] mkConDeclH98 :: Located RdrName -> Maybe [LHsTyVarBndr RdrName]
-> LHsContext RdrName -> HsConDeclDetails RdrName -> LHsContext RdrName -> HsConDeclDetails RdrName
-> ConDecl RdrName -> ConDecl RdrName
......
...@@ -24,7 +24,6 @@ test('T9889', normal, compile, ['']) ...@@ -24,7 +24,6 @@ test('T9889', normal, compile, [''])
test('T9867', normal, compile, ['']) test('T9867', normal, compile, [''])
test('T9975a', normal, compile_fail, ['']) test('T9975a', normal, compile_fail, [''])
test('T9975b', normal, compile, ['']) test('T9975b', normal, compile, [''])
test('T10426', [expect_broken(10426)], compile, [''])
test('T10747', normal, compile, ['']) test('T10747', normal, compile, [''])
test('T10997', [extra_clean(['T10997a.hi', 'T10997a.o'])], multimod_compile, ['T10997', '-v0']) test('T10997', [extra_clean(['T10997a.hi', 'T10997a.o'])], multimod_compile, ['T10997', '-v0'])
test('T10997_1', [extra_clean(['T10997_1a.hi', 'T10997_1a.o'])], multimod_compile, ['T10997_1', '-v0']) test('T10997_1', [extra_clean(['T10997_1a.hi', 'T10997_1a.o'])], multimod_compile, ['T10997_1', '-v0'])
......
T10426.hs:3:9: error:
pattern synonym 'where' clause can not be empty.
In the pattern synonym declaration for: Id
...@@ -26,3 +26,4 @@ test('export-super-class-fail', expect_broken(10653), compile_fail, ['']) ...@@ -26,3 +26,4 @@ test('export-super-class-fail', expect_broken(10653), compile_fail, [''])
test('export-type-synonym', normal, compile_fail, ['']) test('export-type-synonym', normal, compile_fail, [''])
test('export-ps-rec-sel', normal, compile_fail, ['']) test('export-ps-rec-sel', normal, compile_fail, [''])
test('T11053', normal, compile, ['-fwarn-missing-pat-syn-sigs']) test('T11053', normal, compile, ['-fwarn-missing-pat-syn-sigs'])
test('T10426', normal, compile_fail, [''])
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