summaryrefslogtreecommitdiff
path: root/compiler
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
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')
-rw-r--r--compiler/main/DynFlags.hs5
-rw-r--r--compiler/parser/Parser.y27
2 files changed, 28 insertions, 4 deletions
diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs
index 3a14b29806..8cc360fce2 100644
--- a/compiler/main/DynFlags.hs
+++ b/compiler/main/DynFlags.hs
@@ -816,6 +816,7 @@ data WarningFlag =
| Opt_WarnStarIsType -- Since 8.6
| Opt_WarnStarBinder -- Since 8.6
| Opt_WarnImplicitKindVars -- Since 8.6
+ | Opt_WarnSpaceAfterBang
deriving (Eq, Show, Enum)
data Language = Haskell98 | Haskell2010
@@ -3866,6 +3867,7 @@ wWarningFlagsDeps = [
flagSpec "unrecognised-warning-flags" Opt_WarnUnrecognisedWarningFlags,
flagSpec "star-binder" Opt_WarnStarBinder,
flagSpec "star-is-type" Opt_WarnStarIsType,
+ flagSpec "missing-space-after-bang" Opt_WarnSpaceAfterBang,
flagSpec "partial-fields" Opt_WarnPartialFields ]
-- | These @-\<blah\>@ flags can all be reversed with @-no-\<blah\>@
@@ -4564,7 +4566,8 @@ standardWarnings -- see Note [Documenting warning flags]
Opt_WarnUnrecognisedWarningFlags,
Opt_WarnSimplifiableClassConstraints,
Opt_WarnStarBinder,
- Opt_WarnInaccessibleCode
+ Opt_WarnInaccessibleCode,
+ Opt_WarnSpaceAfterBang
]
-- | Things you get with -W
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.