summaryrefslogtreecommitdiff
path: root/testsuite
diff options
context:
space:
mode:
authorRoland Senn <rsx@bluewin.ch>2020-06-17 17:18:26 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-06-25 03:54:48 -0400
commitfe281b27d544920a2c2ddc00f6284006b85ab294 (patch)
tree60b47aea661bc80c8b3b714aaa212a95f13425a3 /testsuite
parentc50ef26edaa537c0a13ac1a574632f9078c5671b (diff)
downloadhaskell-fe281b27d544920a2c2ddc00f6284006b85ab294.tar.gz
Enable maxBound checks for OverloadedLists (Fixes #18172)
Consider the Literal `[256] :: [Data.Word.Word8]` When the `OverloadedLists` extension is not active, then the `ol_ext` field in the `OverLitTc` record that is passed to the function `getIntegralLit` contains the type `Word8`. This is a simple type, and we can use its type constructor immediately for the `warnAboutOverflowedLiterals` function. When the `OverloadedLists` extension is active, then the `ol_ext` field contains the type family `Item [Word8]`. The function `nomaliseType` is used to convert it to the needed type `Word8`.
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/tests/deSugar/should_run/T18172.hs13
-rw-r--r--testsuite/tests/deSugar/should_run/T18172.script22
-rw-r--r--testsuite/tests/deSugar/should_run/T18172.stderr47
-rw-r--r--testsuite/tests/deSugar/should_run/T18172.stdout14
-rw-r--r--testsuite/tests/deSugar/should_run/all.T1
5 files changed, 97 insertions, 0 deletions
diff --git a/testsuite/tests/deSugar/should_run/T18172.hs b/testsuite/tests/deSugar/should_run/T18172.hs
new file mode 100644
index 0000000000..afd21fc9f0
--- /dev/null
+++ b/testsuite/tests/deSugar/should_run/T18172.hs
@@ -0,0 +1,13 @@
+{-# LANGUAGE TypeFamilies #-}
+module T18172 where
+
+import Data.Word
+import GHC.Exts
+
+data Wombat = Wombat [Word8]
+ deriving Show
+
+instance IsList Wombat where
+ type Item Wombat = Word8
+ fromList xs = Wombat xs
+ toList (Wombat xs)= xs
diff --git a/testsuite/tests/deSugar/should_run/T18172.script b/testsuite/tests/deSugar/should_run/T18172.script
new file mode 100644
index 0000000000..f0226e85c4
--- /dev/null
+++ b/testsuite/tests/deSugar/should_run/T18172.script
@@ -0,0 +1,22 @@
+import Data.Word
+[-1] :: [Word8]
+[256] :: [Word8]
+:set -XOverloadedLists
+[-2] :: [Word8]
+[257] :: [Word8]
+import Data.List.NonEmpty
+[-3] :: NonEmpty Word8
+[258] :: NonEmpty Word8
+import Control.Applicative
+ZipList [-4] :: ZipList Word8
+ZipList [259] :: ZipList Word8
+
+[Just 260] :: [Maybe Word8]
+[Just [Just 261]] :: [Maybe ([Maybe Word8])]
+[(262, 65536)] :: [(Word8, Word16)]
+
+[-5..100]::[Word8]
+[100..263]::[Word8]
+
+:l T18172.hs
+Wombat [4, 264, 10]
diff --git a/testsuite/tests/deSugar/should_run/T18172.stderr b/testsuite/tests/deSugar/should_run/T18172.stderr
new file mode 100644
index 0000000000..f5771d8121
--- /dev/null
+++ b/testsuite/tests/deSugar/should_run/T18172.stderr
@@ -0,0 +1,47 @@
+<interactive>:2:3: warning: [-Woverflowed-literals (in -Wdefault)]
+ Literal -1 is out of the Word8 range 0..255
+
+<interactive>:3:2: warning: [-Woverflowed-literals (in -Wdefault)]
+ Literal 256 is out of the Word8 range 0..255
+
+<interactive>:5:3: warning: [-Woverflowed-literals (in -Wdefault)]
+ Literal -2 is out of the Word8 range 0..255
+
+<interactive>:6:2: warning: [-Woverflowed-literals (in -Wdefault)]
+ Literal 257 is out of the Word8 range 0..255
+
+<interactive>:8:3: warning: [-Woverflowed-literals (in -Wdefault)]
+ Literal -3 is out of the Word8 range 0..255
+
+<interactive>:9:2: warning: [-Woverflowed-literals (in -Wdefault)]
+ Literal 258 is out of the Word8 range 0..255
+
+<interactive>:11:11: warning: [-Woverflowed-literals (in -Wdefault)]
+ Literal -4 is out of the Word8 range 0..255
+
+<interactive>:12:10: warning: [-Woverflowed-literals (in -Wdefault)]
+ Literal 259 is out of the Word8 range 0..255
+
+<interactive>:14:7: warning: [-Woverflowed-literals (in -Wdefault)]
+ Literal 260 is out of the Word8 range 0..255
+
+<interactive>:15:13: warning: [-Woverflowed-literals (in -Wdefault)]
+ Literal 261 is out of the Word8 range 0..255
+
+<interactive>:16:3: warning: [-Woverflowed-literals (in -Wdefault)]
+ Literal 262 is out of the Word8 range 0..255
+
+<interactive>:16:8: warning: [-Woverflowed-literals (in -Wdefault)]
+ Literal 65536 is out of the Word16 range 0..65535
+
+<interactive>:18:3: warning: [-Woverflowed-literals (in -Wdefault)]
+ Literal -5 is out of the Word8 range 0..255
+
+<interactive>:19:1: warning: [-Wempty-enumerations (in -Wdefault)]
+ Enumeration is empty
+
+<interactive>:19:7: warning: [-Woverflowed-literals (in -Wdefault)]
+ Literal 263 is out of the Word8 range 0..255
+
+<interactive>:22:12: warning: [-Woverflowed-literals (in -Wdefault)]
+ Literal 264 is out of the Word8 range 0..255
diff --git a/testsuite/tests/deSugar/should_run/T18172.stdout b/testsuite/tests/deSugar/should_run/T18172.stdout
new file mode 100644
index 0000000000..8f30df2597
--- /dev/null
+++ b/testsuite/tests/deSugar/should_run/T18172.stdout
@@ -0,0 +1,14 @@
+[255]
+[0]
+[254]
+[1]
+253 :| []
+2 :| []
+ZipList {getZipList = [252]}
+ZipList {getZipList = [3]}
+[Just 4]
+[Just [Just 5]]
+[(6,0)]
+[]
+[]
+Wombat [4,8,10]
diff --git a/testsuite/tests/deSugar/should_run/all.T b/testsuite/tests/deSugar/should_run/all.T
index 214f088aea..6245f9caf5 100644
--- a/testsuite/tests/deSugar/should_run/all.T
+++ b/testsuite/tests/deSugar/should_run/all.T
@@ -65,3 +65,4 @@ test('T11747', normal, compile_and_run, ['-dcore-lint'])
test('T12595', normal, compile_and_run, [''])
test('T13285', normal, compile_and_run, [''])
test('T18151', normal, compile_and_run, [''])
+test('T18172', [], ghci_script, ['T18172.script'])