Commit 3fdabe98 authored by ruperthorlick's avatar ruperthorlick Committed by Ben Gamari

Changed OverLit warnings to work with negative literals (#13257)

Test Plan: Validate, check generated warnings

Reviewers: austin, bgamari, dfeuer

Reviewed By: bgamari, dfeuer

Subscribers: dfeuer, thomie

Differential Revision: https://phabricator.haskell.org/D3281
parent 016b10c5
......@@ -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'] }
......
......@@ -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"
......
module T13257 where
import Data.Int
int8 = -128 :: Int8
word = -1 :: Word
T13257.hs:6:11: warning: [-Woverflowed-literals (in -Wdefault)]
Literal -1 is out of the Word range 0..18446744073709551615
......@@ -97,3 +97,4 @@ test('T12950', normal, compile, [''])
test('T13043', normal, compile, [''])
test('T13215', normal, compile, [''])
test('T13290', normal, compile, [''])
test('T13257', normal, compile, [''])
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment