Warn on all out-of-range literals in pats/exprs
authorAlec Theriault <alec.theriault@gmail.com>
Mon, 3 Dec 2018 12:03:44 +0000 (07:03 -0500)
committerRyan Scott <ryan.gl.scott@gmail.com>
Mon, 3 Dec 2018 12:03:44 +0000 (07:03 -0500)
commit75a8349b2a7d0142d3d687837caf5a95bbb4368d
tree7a1c14b1ba4357dcc032d2d32a10039b8c3f1cd0
parent93a3f9070d5d69ad6a28fe94ccccd20c54609698
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
19 files changed:
compiler/deSugar/DsExpr.hs
compiler/deSugar/DsMonad.hs
compiler/deSugar/Match.hs
compiler/deSugar/MatchCon.hs
compiler/deSugar/MatchLit.hs
compiler/prelude/TysPrim.hs
docs/users_guide/8.8.1-notes.rst
libraries/base/GHC/Enum.hs
testsuite/tests/warnings/should_compile/Overflow.hs [new file with mode: 0644]
testsuite/tests/warnings/should_compile/Overflow.stderr [new file with mode: 0644]
testsuite/tests/warnings/should_compile/T10930.hs [new file with mode: 0644]
testsuite/tests/warnings/should_compile/T10930.stderr [new file with mode: 0644]
testsuite/tests/warnings/should_compile/T10930b.hs [new file with mode: 0644]
testsuite/tests/warnings/should_compile/T10930b.stderr [new file with mode: 0644]
testsuite/tests/warnings/should_compile/T13256.hs [new file with mode: 0644]
testsuite/tests/warnings/should_compile/T13256.stderr [new file with mode: 0644]
testsuite/tests/warnings/should_compile/T15460.hs [new file with mode: 0644]
testsuite/tests/warnings/should_compile/T15460.stderr [new file with mode: 0644]
testsuite/tests/warnings/should_compile/all.T