Ticket #8542: 0001-Improve-warning-on-overflowed-literals-8542.patch

File 0001-Improve-warning-on-overflowed-literals-8542.patch, 1.7 KB (added by monoidal, 17 months ago)
  • compiler/deSugar/MatchLit.lhs

    From d5260f4afb26ce12646cfa6575b3c9d57f0324d1 Mon Sep 17 00:00:00 2001
    From: Krzysztof Gogolewski <[email protected]>
    Date: Mon, 18 Nov 2013 13:41:53 +0100
    Subject: [PATCH] Improve warning on overflowed literals (#8542)
    
    ---
     compiler/deSugar/MatchLit.lhs | 16 +++++++++++-----
     1 file changed, 11 insertions(+), 5 deletions(-)
    
    diff --git a/compiler/deSugar/MatchLit.lhs b/compiler/deSugar/MatchLit.lhs
    index 2842b7b..bfacffe 100644
    a b warnAboutOverflowedLiterals dflags lit 
    159159 , Just (i, tc) <- getIntegralLit lit 
    160160 , let check :: forall a. (Bounded a, Integral a) => a -> DsM () 
    161161       check _proxy 
    162          = when (i < toInteger (minBound :: a) || 
    163                  i > toInteger (maxBound :: a)) $ 
    164            warnDs (ptext (sLit "Literal") <+> integer i <+> 
    165                    ptext (sLit "of type") <+> ppr tc <+> 
    166                    ptext (sLit "overflows")) 
     162         = when (i < minB || i > maxB) $ do 
     163           warnDs (vcat [ptext (sLit "Literal") <+> integer i <+> 
     164                   ptext (sLit "of type") <+> ppr tc <+> ptext (sLit "overflows"), 
     165                   sug]) 
     166         where minB = toInteger (minBound :: a) 
     167               maxB = toInteger (maxBound :: a) 
     168               sug | minB == -i 
     169                   , i > 0 
     170                   , not (xopt Opt_NegativeLiterals dflags) 
     171                       = ptext (sLit "If you are attempting to write a negative literal, use NegativeLiterals") 
     172                   | otherwise = empty 
    167173  = if      tc == intTyConName    then check (undefined :: Int) 
    168174    else if tc == int8TyConName   then check (undefined :: Int8) 
    169175    else if tc == int16TyConName  then check (undefined :: Int16)