File tree Expand file tree Collapse file tree 4 files changed +62
-0
lines changed
message-index/messages/GHC-97441 Expand file tree Collapse file tree 4 files changed +62
-0
lines changed Original file line number Diff line number Diff line change
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 )
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
+ ```
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments