summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compiler/GHC/Parser/Lexer.x13
-rw-r--r--testsuite/tests/parser/should_fail/T18251e.hs3
-rw-r--r--testsuite/tests/parser/should_fail/T18251e.stderr5
-rw-r--r--testsuite/tests/parser/should_fail/all.T1
4 files changed, 18 insertions, 4 deletions
diff --git a/compiler/GHC/Parser/Lexer.x b/compiler/GHC/Parser/Lexer.x
index 8245974db6..5633fd0b0d 100644
--- a/compiler/GHC/Parser/Lexer.x
+++ b/compiler/GHC/Parser/Lexer.x
@@ -366,15 +366,20 @@ $tab { warnTab }
-- "special" symbols
<0> {
- "[|" / { ifExtension ThQuotesBit } { token (ITopenExpQuote NoE NormalSyntax) }
- "[||" / { ifExtension ThQuotesBit } { token (ITopenTExpQuote NoE) }
+
+ -- Don't check ThQuotesBit here as the renamer can produce a better
+ -- error message than the lexer (see the thQuotesEnabled check in rnBracket).
+ "[|" { token (ITopenExpQuote NoE NormalSyntax) }
+ "[||" { token (ITopenTExpQuote NoE) }
+ "|]" { token (ITcloseQuote NormalSyntax) }
+ "||]" { token ITcloseTExpQuote }
+
+ -- Check ThQuotesBit here as to not steal syntax.
"[e|" / { ifExtension ThQuotesBit } { token (ITopenExpQuote HasE NormalSyntax) }
"[e||" / { ifExtension ThQuotesBit } { token (ITopenTExpQuote HasE) }
"[p|" / { ifExtension ThQuotesBit } { token ITopenPatQuote }
"[d|" / { ifExtension ThQuotesBit } { layout_token ITopenDecQuote }
"[t|" / { ifExtension ThQuotesBit } { token ITopenTypQuote }
- "|]" / { ifExtension ThQuotesBit } { token (ITcloseQuote NormalSyntax) }
- "||]" / { ifExtension ThQuotesBit } { token ITcloseTExpQuote }
"[" @varid "|" / { ifExtension QqBit } { lex_quasiquote_tok }
diff --git a/testsuite/tests/parser/should_fail/T18251e.hs b/testsuite/tests/parser/should_fail/T18251e.hs
new file mode 100644
index 0000000000..c471a9601c
--- /dev/null
+++ b/testsuite/tests/parser/should_fail/T18251e.hs
@@ -0,0 +1,3 @@
+module T18251e where
+
+a = [| id |]
diff --git a/testsuite/tests/parser/should_fail/T18251e.stderr b/testsuite/tests/parser/should_fail/T18251e.stderr
new file mode 100644
index 0000000000..7b869c09c8
--- /dev/null
+++ b/testsuite/tests/parser/should_fail/T18251e.stderr
@@ -0,0 +1,5 @@
+
+T18251e.hs:3:5: error:
+ • Syntax error on [| id |]
+ Perhaps you intended to use TemplateHaskell or TemplateHaskellQuotes
+ • In the Template Haskell quotation [| id |]
diff --git a/testsuite/tests/parser/should_fail/all.T b/testsuite/tests/parser/should_fail/all.T
index 3b31682cb2..9142eb0393 100644
--- a/testsuite/tests/parser/should_fail/all.T
+++ b/testsuite/tests/parser/should_fail/all.T
@@ -171,4 +171,5 @@ test('T18251a', normal, compile_fail, [''])
test('T18251b', normal, compile_fail, [''])
test('T18251c', normal, compile_fail, [''])
test('T18251d', normal, compile_fail, [''])
+test('T18251e', normal, compile_fail, [''])
test('T18251f', normal, compile_fail, [''])