From 05ed304ef456e3e2a22355bd25a011a10fcff29e Mon Sep 17 00:00:00 2001 From: Kevin Buhr Date: Sat, 27 Jul 2019 13:25:31 -0500 Subject: Disallow (->) as a data constructor in "data" declaration (fixes #16999) --- compiler/parser/RdrHsSyn.hs | 4 +++- testsuite/tests/parser/should_fail/T16999.hs | 6 ++++++ testsuite/tests/parser/should_fail/T16999.stderr | 2 ++ testsuite/tests/parser/should_fail/all.T | 2 ++ 4 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 testsuite/tests/parser/should_fail/T16999.hs create mode 100644 testsuite/tests/parser/should_fail/T16999.stderr diff --git a/compiler/parser/RdrHsSyn.hs b/compiler/parser/RdrHsSyn.hs index a574fbe338..defad0fb51 100644 --- a/compiler/parser/RdrHsSyn.hs +++ b/compiler/parser/RdrHsSyn.hs @@ -565,13 +565,15 @@ done. tyConToDataCon :: SrcSpan -> RdrName -> Either (SrcSpan, SDoc) (Located RdrName) tyConToDataCon loc tc | isTcOcc occ || isDataOcc occ - , isLexCon (occNameFS occ) + , isLexCon cs + , cs /= fsLit "->" -- Fixes #16999 = return (cL loc (setRdrNameSpace tc srcDataName)) | otherwise = Left (loc, msg) where occ = rdrNameOcc tc + cs = occNameFS occ msg = text "Not a data constructor:" <+> quotes (ppr tc) mkPatSynMatchGroup :: Located RdrName diff --git a/testsuite/tests/parser/should_fail/T16999.hs b/testsuite/tests/parser/should_fail/T16999.hs new file mode 100644 index 0000000000..d43612d035 --- /dev/null +++ b/testsuite/tests/parser/should_fail/T16999.hs @@ -0,0 +1,6 @@ +module T16999 where + +data Type + = TBool + | TInt + | (->) Type Type diff --git a/testsuite/tests/parser/should_fail/T16999.stderr b/testsuite/tests/parser/should_fail/T16999.stderr new file mode 100644 index 0000000000..f9f1569695 --- /dev/null +++ b/testsuite/tests/parser/should_fail/T16999.stderr @@ -0,0 +1,2 @@ + +T16999.hs:6:5: Not a data constructor: ‘->’ diff --git a/testsuite/tests/parser/should_fail/all.T b/testsuite/tests/parser/should_fail/all.T index 2fc7f3d326..5b919e1a2d 100644 --- a/testsuite/tests/parser/should_fail/all.T +++ b/testsuite/tests/parser/should_fail/all.T @@ -161,3 +161,5 @@ test('patFail006', normal, compile_fail, ['']) test('patFail007', normal, compile_fail, ['']) test('patFail008', normal, compile_fail, ['']) test('patFail009', normal, compile_fail, ['']) + +test('T16999', normal, compile_fail, ['']) -- cgit v1.2.1