summaryrefslogtreecommitdiff
path: root/compiler/deSugar/DsMonad.hs
diff options
context:
space:
mode:
authorAlec Theriault <alec.theriault@gmail.com>2018-12-03 07:03:44 -0500
committerRyan Scott <ryan.gl.scott@gmail.com>2018-12-03 07:03:44 -0500
commit75a8349b2a7d0142d3d687837caf5a95bbb4368d (patch)
tree7a1c14b1ba4357dcc032d2d32a10039b8c3f1cd0 /compiler/deSugar/DsMonad.hs
parent93a3f9070d5d69ad6a28fe94ccccd20c54609698 (diff)
downloadhaskell-75a8349b2a7d0142d3d687837caf5a95bbb4368d.tar.gz
Warn on all out-of-range literals in pats/exprs
Summary: These changes were motivated by #13256. While poking around, I realized we weren't very consistent in our "-Woverflowed-literals" warnings. This patch fixes that by: * warning earlier on in the pipeline (ie. before we've desugared 'Int' patterns into 'I# Int#') * handling 'HsLit' as well as 'HsOverLit' (this covers unboxed literals) * covering more pattern / expression forms 4/6 of the warnings in the 'Overflow' test are due to this patch. The other two are mostly for completeness. Also fixed a missing empty-enumeration warning for 'Natural'. This warnings were tripped up by the 'Bounded Word' instance (see #9505), but the fix was obvious and simple: use unboxed word literals. Test Plan: make TEST=Overflow && make TEST=T10930 Reviewers: hvr, bgamari, RyanGlScott Reviewed By: RyanGlScott Subscribers: RyanGlScott, rwbarton, carter GHC Trac Issues: #13256, #10930 Differential Revision: https://phabricator.haskell.org/D5181
Diffstat (limited to 'compiler/deSugar/DsMonad.hs')
-rw-r--r--compiler/deSugar/DsMonad.hs26
1 files changed, 20 insertions, 6 deletions
diff --git a/compiler/deSugar/DsMonad.hs b/compiler/deSugar/DsMonad.hs
index 5d597912e5..7742f8cd76 100644
--- a/compiler/deSugar/DsMonad.hs
+++ b/compiler/deSugar/DsMonad.hs
@@ -66,6 +66,7 @@ import PrelNames
import RdrName
import HscTypes
import Bag
+import BasicTypes ( Origin )
import DataCon
import ConLike
import TyCon
@@ -104,14 +105,27 @@ instance Outputable DsMatchContext where
ppr (DsMatchContext hs_match ss) = ppr ss <+> pprMatchContext hs_match
data EquationInfo
- = EqnInfo { eqn_pats :: [Pat GhcTc], -- The patterns for an eqn
- -- NB: We have /already/ applied decideBangHood to
- -- these patterns. See Note [decideBangHood] in DsUtils
-
- eqn_rhs :: MatchResult } -- What to do after match
+ = EqnInfo { eqn_pats :: [Pat GhcTc]
+ -- ^ The patterns for an equation
+ --
+ -- NB: We have /already/ applied 'decideBangHood' to
+ -- these patterns. See Note [decideBangHood] in "DsUtils"
+
+ , eqn_orig :: Origin
+ -- ^ Was this equation present in the user source?
+ --
+ -- This helps us avoid warnings on patterns that GHC elaborated.
+ --
+ -- For instance, the pattern @-1 :: Word@ gets desugared into
+ -- @W# -1## :: Word@, but we shouldn't warn about an overflowed
+ -- literal for /both/ of these cases.
+
+ , eqn_rhs :: MatchResult
+ -- ^ What to do after match
+ }
instance Outputable EquationInfo where
- ppr (EqnInfo pats _) = ppr pats
+ ppr (EqnInfo pats _ _) = ppr pats
type DsWrapper = CoreExpr -> CoreExpr
idDsWrapper :: DsWrapper