[commit: ghc] master: Suggest enabling PatternSynonyms (#10943) (1e8d1f1)
git at git.haskell.org
git at git.haskell.org
Thu Oct 22 11:40:05 UTC 2015
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/1e8d1f1c6d85457c786b50b1e054facdb61cbae1/ghc
>---------------------------------------------------------------
commit 1e8d1f1c6d85457c786b50b1e054facdb61cbae1
Author: Moritz Kiefer <moritz.kiefer at purelyfunctional.org>
Date: Thu Oct 22 13:40:41 2015 +0200
Suggest enabling PatternSynonyms (#10943)
Suggest enabling PatternSynonyms if we find an invalid
signature that looks like a pattern synonym.
Reviewed By: austin, thomie
Differential Revision: https://phabricator.haskell.org/D1347
>---------------------------------------------------------------
1e8d1f1c6d85457c786b50b1e054facdb61cbae1
compiler/parser/RdrHsSyn.hs | 14 +++++++++-----
testsuite/tests/parser/should_fail/NoPatternSynonyms.hs | 3 +++
.../tests/parser/should_fail/NoPatternSynonyms.stderr | 4 ++++
testsuite/tests/parser/should_fail/all.T | 1 +
4 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/compiler/parser/RdrHsSyn.hs b/compiler/parser/RdrHsSyn.hs
index e64a575..a1577a7 100644
--- a/compiler/parser/RdrHsSyn.hs
+++ b/compiler/parser/RdrHsSyn.hs
@@ -947,11 +947,14 @@ checkValSig lhs@(L l _) ty
ppr lhs <+> text "::" <+> ppr ty)
$$ text hint)
where
- hint = if foreign_RDR `looks_like` lhs
- then "Perhaps you meant to use ForeignFunctionInterface?"
- else if default_RDR `looks_like` lhs
- then "Perhaps you meant to use DefaultSignatures?"
- else "Should be of form <variable> :: <type>"
+ hint | foreign_RDR `looks_like` lhs =
+ "Perhaps you meant to use ForeignFunctionInterface?"
+ | default_RDR `looks_like` lhs =
+ "Perhaps you meant to use DefaultSignatures?"
+ | pattern_RDR `looks_like` lhs =
+ "Perhaps you meant to use PatternSynonyms?"
+ | otherwise =
+ "Should be of form <variable> :: <type>"
-- A common error is to forget the ForeignFunctionInterface flag
-- so check for that, and suggest. cf Trac #3805
-- Sadly 'foreign import' still barfs 'parse error' because 'import' is a keyword
@@ -961,6 +964,7 @@ checkValSig lhs@(L l _) ty
foreign_RDR = mkUnqual varName (fsLit "foreign")
default_RDR = mkUnqual varName (fsLit "default")
+ pattern_RDR = mkUnqual varName (fsLit "pattern")
checkDoAndIfThenElse :: LHsExpr RdrName
diff --git a/testsuite/tests/parser/should_fail/NoPatternSynonyms.hs b/testsuite/tests/parser/should_fail/NoPatternSynonyms.hs
new file mode 100644
index 0000000..ef6f57f
--- /dev/null
+++ b/testsuite/tests/parser/should_fail/NoPatternSynonyms.hs
@@ -0,0 +1,3 @@
+module NoPatternSynonyms where
+
+pattern P :: G Int
diff --git a/testsuite/tests/parser/should_fail/NoPatternSynonyms.stderr b/testsuite/tests/parser/should_fail/NoPatternSynonyms.stderr
new file mode 100644
index 0000000..b31ec83
--- /dev/null
+++ b/testsuite/tests/parser/should_fail/NoPatternSynonyms.stderr
@@ -0,0 +1,4 @@
+
+NoPatternSynonyms.hs:3:1: error:
+ Invalid type signature: pattern P :: G Int
+ Perhaps you meant to use PatternSynonyms?
diff --git a/testsuite/tests/parser/should_fail/all.T b/testsuite/tests/parser/should_fail/all.T
index 13fb738..66945dd 100644
--- a/testsuite/tests/parser/should_fail/all.T
+++ b/testsuite/tests/parser/should_fail/all.T
@@ -68,6 +68,7 @@ test('T3811e', normal, compile_fail, [''])
test('T3811f', normal, compile_fail, [''])
test('T3811g', normal, compile_fail, [''])
test('NoDoAndIfThenElse', normal, compile_fail, [''])
+test('NoPatternSynonyms', normal, compile_fail, [''])
test('NondecreasingIndentationFail', normal, compile_fail, [''])
test('readFailTraditionalRecords1', normal, compile_fail, [''])
test('readFailTraditionalRecords2', normal, compile_fail, [''])
More information about the ghc-commits
mailing list