Skip to content

Commit 879c95f

Browse files
committed
Document DsOverflowedLiterals -> 97441 (closes #2)
1 parent e95a1d6 commit 879c95f

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module Main where
2+
3+
import Data.Word (Word8)
4+
5+
main :: IO ()
6+
main = do
7+
-- Word8 can represent values in range (0,255)
8+
-- prints 255
9+
print (255 :: Word8)
10+
11+
-- Int can represent values in range (-9223372036854775808,9223372036854775807)
12+
-- prints 9223372036854775807
13+
print (9223372036854775807 :: Int)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module Main where
2+
3+
import Data.Word (Word8)
4+
5+
main :: IO ()
6+
main = do
7+
-- Word8 can represent values in range (0,255)
8+
-- prints 2 due to overflow
9+
print (258 :: Word8)
10+
-- ^ value is 3 larger than maxBound so it will wrap around 0 -> 1 -> 2
11+
12+
-- Int can represent values in range (-9223372036854775808,9223372036854775807)
13+
-- prints -9223372036854775799 due to overflow
14+
print (9223372036854775817 :: Int)
15+
-- ^ value is 10 larger than maxBound
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: Overflowed Literal
3+
---
4+
5+
## Error Message
6+
```
7+
before/OverflowedLiterals.hs:9:12: warning: [GHC-97441] [-Woverflowed-literals]
8+
Literal 258 is out of the Word8 range 0..255
9+
|
10+
9 | print (258 :: Word8)
11+
| ^^^
12+
13+
before/OverflowedLiterals.hs:14:12: warning: [GHC-97441] [-Woverflowed-literals]
14+
Literal 9223372036854775817 is out of the Int range -9223372036854775808..9223372036854775807
15+
|
16+
14 | print (9223372036854775817 :: Int)
17+
| ^^^^^^^^^^^^^^^^^^^
18+
19+
```
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
title: Overflowed Literal
3+
summary: Literal overflowing range of supported values
4+
severity: warning
5+
introduced: 9.6.1
6+
flag: -Woverflowed-literals
7+
---
8+
9+
Warning emitted if a literal (constant value in the source code) will overflow.
10+
This doesn't cause error at runtime, but might cause confusion because overflowed value might be different than what you expect.
11+
12+
To fix the warning you can:
13+
14+
- Use different value for the literal so that it fits within the range supported by its type
15+
- Use different type, which is capable of representing the value

0 commit comments

Comments
 (0)