summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Buhr <buhr@asaurus.net>2019-07-27 13:25:31 -0500
committerKevin Buhr <buhr@asaurus.net>2019-07-27 13:25:31 -0500
commit05ed304ef456e3e2a22355bd25a011a10fcff29e (patch)
treebe270cd462f07609e2cf1c90076f12749f1e52d6
parent26314386789e3717427bab4bcb97755535bb12d4 (diff)
downloadhaskell-wip/B16999.tar.gz
Disallow (->) as a data constructor in "data" declaration (fixes #16999)wip/B16999
-rw-r--r--compiler/parser/RdrHsSyn.hs4
-rw-r--r--testsuite/tests/parser/should_fail/T16999.hs6
-rw-r--r--testsuite/tests/parser/should_fail/T16999.stderr2
-rw-r--r--testsuite/tests/parser/should_fail/all.T2
4 files changed, 13 insertions, 1 deletions
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, [''])