summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2019-10-07 19:30:55 -0400
committerBen Gamari <ben@smart-cactus.org>2019-10-08 13:46:58 -0400
commit4a59807d2fec146abdb544eb13f786c3436894b6 (patch)
treee5245d50950c713fadd32ef85e750f85a85ac039
parent241921a0c238a047326b0c0f599f1c24222ff66c (diff)
downloadhaskell-wip/T16999.tar.gz
rename: Don't allow binding of built-in names as dataconswip/T16999
Fixes #16999 by adding a check in RnNames.checkConName to ensure that the name doesn't shadow built-in syntax.
-rw-r--r--compiler/rename/RnNames.hs6
-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, 15 insertions, 1 deletions
diff --git a/compiler/rename/RnNames.hs b/compiler/rename/RnNames.hs
index 7b9a385e48..d30886cb04 100644
--- a/compiler/rename/RnNames.hs
+++ b/compiler/rename/RnNames.hs
@@ -53,6 +53,7 @@ import Outputable
import Maybes
import SrcLoc
import BasicTypes ( TopLevelFlag(..), StringLiteral(..) )
+import TysWiredIn ( isBuiltInOcc_maybe )
import Util
import FastString
import FastStringEnv
@@ -1774,7 +1775,10 @@ packageImportErr
-- from interface files, which always print in prefix form
checkConName :: RdrName -> TcRn ()
-checkConName name = checkErr (isRdrDataCon name) (badDataCon name)
+checkConName name = checkErr (isRdrDataCon name && is_okay) (badDataCon name)
+ where
+ -- Don't allow binding of built-in names (#16999)
+ is_okay = isNothing $ isBuiltInOcc_maybe $ rdrNameOcc name
badDataCon :: RdrName -> SDoc
badDataCon name
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, [''])