Changed OverLit warnings to work with negative literals (#13257)
authorRupert Horlick <ruperthorlick@gmail.com>
Mon, 6 Mar 2017 18:43:34 +0000 (13:43 -0500)
committerBen Gamari <ben@smart-cactus.org>
Mon, 6 Mar 2017 22:23:01 +0000 (17:23 -0500)
Test Plan: Validate, check generated warnings

Reviewers: austin, bgamari, dfeuer

Reviewed By: bgamari, dfeuer

Subscribers: dfeuer, thomie

Differential Revision: https://phabricator.haskell.org/D3281

compiler/deSugar/DsExpr.hs
compiler/deSugar/MatchLit.hs
testsuite/tests/deSugar/should_compile/T13257.hs [new file with mode: 0644]
testsuite/tests/deSugar/should_compile/T13257.stderr [new file with mode: 0644]
testsuite/tests/deSugar/should_compile/all.T
testsuite/tests/numeric/should_compile/T8542.stderr

index 28254c9..faf562e 100644 (file)
@@ -271,6 +271,15 @@ dsExpr (HsWrap co_fn e)
        ; warnAboutIdentities dflags e' (exprType wrapped_e)
        ; return wrapped_e }
 
+dsExpr (NegApp (L loc (HsOverLit lit@(OverLit { ol_val = HsIntegral src i })))
+                neg_expr)
+  = do { expr' <- putSrcSpanDs loc $ do
+          { dflags <- getDynFlags
+          ; warnAboutOverflowedLiterals dflags
+                                        (lit { ol_val = HsIntegral src (-i) })
+          ; dsOverLit' dflags lit }
+       ; dsSyntaxExpr neg_expr [expr'] }
+
 dsExpr (NegApp expr neg_expr)
   = do { expr' <- dsLExpr expr
        ; dsSyntaxExpr neg_expr [expr'] }
index 2e9a523..6ed34f4 100644 (file)
@@ -8,10 +8,11 @@ Pattern-matching literal patterns
 
 {-# LANGUAGE CPP, ScopedTypeVariables #-}
 
-module MatchLit ( dsLit, dsOverLit, hsLitKey
+module MatchLit ( dsLit, dsOverLit, dsOverLit', hsLitKey
                 , tidyLitPat, tidyNPat
                 , matchLiterals, matchNPlusKPats, matchNPats
-                , warnAboutIdentities, warnAboutEmptyEnumerations
+                , warnAboutIdentities, warnAboutOverflowedLiterals
+                , warnAboutEmptyEnumerations
                 ) where
 
 #include "HsVersions.h"
diff --git a/testsuite/tests/deSugar/should_compile/T13257.hs b/testsuite/tests/deSugar/should_compile/T13257.hs
new file mode 100644 (file)
index 0000000..b9188df
--- /dev/null
@@ -0,0 +1,6 @@
+module T13257 where
+
+  import Data.Int
+
+  int8 = -128 :: Int8
+  word = -1 :: Word
diff --git a/testsuite/tests/deSugar/should_compile/T13257.stderr b/testsuite/tests/deSugar/should_compile/T13257.stderr
new file mode 100644 (file)
index 0000000..93412f1
--- /dev/null
@@ -0,0 +1,3 @@
+
+T13257.hs:6:11: warning: [-Woverflowed-literals (in -Wdefault)]
+    Literal -1 is out of the Word range 0..18446744073709551615
index 7694fb9..7a39b1e 100644 (file)
@@ -97,3 +97,4 @@ test('T12950', normal, compile, [''])
 test('T13043', normal, compile, [''])
 test('T13215', normal, compile, [''])
 test('T13290', normal, compile, [''])
+test('T13257', normal, compile, [''])
index f414382..699ba5d 100644 (file)
@@ -1,8 +1,4 @@
 
-T8542.hs:6:6: warning: [-Woverflowed-literals (in -Wdefault)]
-    Literal 128 is out of the Int8 range -128..127
-    If you are trying to write a large negative literal, use NegativeLiterals
-
 T8542.hs:9:5: warning: [-Woverflowed-literals (in -Wdefault)]
     Literal 128 is out of the Int8 range -128..127
     If you are trying to write a large negative literal, use NegativeLiterals