summaryrefslogtreecommitdiff
path: root/compiler/parser
diff options
context:
space:
mode:
authorSasa Bogicevic <t4nt0r@protonmail.com>2018-10-15 13:47:48 -0400
committerBen Gamari <ben@smart-cactus.org>2018-10-15 17:41:48 -0400
commit0b0cb484eb0b51bf5485dfadff7cd8a079ceb16e (patch)
tree8ae642d14e0970391bf713c2a400061f45bd3c04 /compiler/parser
parent846fe90464a1916df4ea72659255963a596eec84 (diff)
downloadhaskell-0b0cb484eb0b51bf5485dfadff7cd8a079ceb16e.tar.gz
Surprising error message with bang pattern
Reviewers: bgamari, alanz Reviewed By: bgamari Subscribers: sgraf, mpickering, rwbarton, thomie, carter GHC Trac Issues: #13600 Differential Revision: https://phabricator.haskell.org/D5040
Diffstat (limited to 'compiler/parser')
-rw-r--r--compiler/parser/Parser.y27
1 files changed, 24 insertions, 3 deletions
diff --git a/compiler/parser/Parser.y b/compiler/parser/Parser.y
index 74db997bbb..d7aef8d77f 100644
--- a/compiler/parser/Parser.y
+++ b/compiler/parser/Parser.y
@@ -29,7 +29,7 @@ module Parser (parseModule, parseSignature, parseImport, parseStatement, parseBa
parseType, parseHeader) where
-- base
-import Control.Monad ( unless, liftM )
+import Control.Monad ( unless, liftM, when )
import GHC.Exts
import Data.Char
import Control.Monad ( mplus )
@@ -2483,8 +2483,14 @@ infixexp :: { LHsExpr GhcPs }
infixexp_top :: { LHsExpr GhcPs }
: exp10_top { $1 }
| infixexp_top qop exp10_top
- {% ams (sLL $1 $> (OpApp noExt $1 $2 $3))
- [mj AnnVal $2] }
+ {% do { when (srcSpanEnd (getLoc $2)
+ == srcSpanStart (getLoc $3)
+ && checkIfBang $2) $
+ warnSpaceAfterBang (comb2 $2 $3);
+ ams (sLL $1 $> (OpApp noExt $1 $2 $3))
+ [mj AnnVal $2]
+ }
+ }
exp10_top :: { LHsExpr GhcPs }
@@ -3705,6 +3711,21 @@ hintExplicitForall' span = do
, text "extension to enable explicit-forall syntax: forall <tvs>. <type>"
]
+checkIfBang :: LHsExpr GhcPs -> Bool
+checkIfBang (L _ (HsVar _ (L _ op))) = op == bang_RDR
+checkIfBang _ = False
+
+-- | Warn about missing space after bang
+warnSpaceAfterBang :: SrcSpan -> P ()
+warnSpaceAfterBang span = do
+ bang_on <- extension bangPatEnabled
+ unless bang_on $
+ addWarning Opt_WarnSpaceAfterBang span msg
+ where
+ msg = text "Did you forget to enable BangPatterns?" $$
+ text "If you mean to bind (!) then perhaps you want" $$
+ text "to add a space after the bang for clarity."
+
-- When two single quotes don't followed by tyvar or gtycon, we report the
-- error as empty character literal, or TH quote that missing proper type
-- variable or constructor. See Trac #13450.