diff options
author | Ryan Scott <ryan.gl.scott@gmail.com> | 2021-04-18 11:42:20 -0400 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-04-18 20:13:01 -0400 |
commit | 0b398d554f0cc2f5341ccf62f40347c9c025767f (patch) | |
tree | c2dee88c65787c41f326bf5f5340d8a8f802ea81 /libraries/base/tests | |
parent | 0165b0295c81247ae97a4689ae6e1fbd2fbc9311 (diff) | |
download | haskell-0b398d554f0cc2f5341ccf62f40347c9c025767f.tar.gz |
Use correct precedence in Complex's Read1/Show1 instances
Fixes #19719.
Diffstat (limited to 'libraries/base/tests')
-rw-r--r-- | libraries/base/tests/T19719.hs | 26 | ||||
-rw-r--r-- | libraries/base/tests/T19719.stdout | 16 | ||||
-rw-r--r-- | libraries/base/tests/all.T | 1 |
3 files changed, 43 insertions, 0 deletions
diff --git a/libraries/base/tests/T19719.hs b/libraries/base/tests/T19719.hs new file mode 100644 index 0000000000..613f92ad6c --- /dev/null +++ b/libraries/base/tests/T19719.hs @@ -0,0 +1,26 @@ +module Main (main) where + +import Data.Complex (Complex(..)) +import Data.Functor.Classes (readPrec1, showsPrec1) +import Text.ParserCombinators.ReadPrec (readPrec_to_S) +import Text.Read (Read(..)) + +comp :: Complex Int +comp = 1 :+ 1 + +compareInstances :: Int -> IO () +compareInstances p = do + let precBanner = " (at precedence " ++ show p ++ ")" + putStrLn $ "Read vs. Read1" ++ precBanner + print (readPrec_to_S readPrec p "1 :+ 1" :: [(Complex Int, String)]) + print (readPrec_to_S readPrec1 p "1 :+ 1" :: [(Complex Int, String)]) + putStrLn "" + putStrLn $ "Show vs. Show1" ++ precBanner + putStrLn $ showsPrec p comp "" + putStrLn $ showsPrec1 p comp "" + putStrLn "" + +main :: IO () +main = do + compareInstances 6 + compareInstances 7 diff --git a/libraries/base/tests/T19719.stdout b/libraries/base/tests/T19719.stdout new file mode 100644 index 0000000000..8f59bd40f0 --- /dev/null +++ b/libraries/base/tests/T19719.stdout @@ -0,0 +1,16 @@ +Read vs. Read1 (at precedence 6) +[(1 :+ 1,"")] +[(1 :+ 1,"")] + +Show vs. Show1 (at precedence 6) +1 :+ 1 +1 :+ 1 + +Read vs. Read1 (at precedence 7) +[] +[] + +Show vs. Show1 (at precedence 7) +(1 :+ 1) +(1 :+ 1) + diff --git a/libraries/base/tests/all.T b/libraries/base/tests/all.T index b02d77ef11..7ea69949e2 100644 --- a/libraries/base/tests/all.T +++ b/libraries/base/tests/all.T @@ -263,3 +263,4 @@ test('T16643', normal, compile_and_run, ['']) test('clamp', normal, compile_and_run, ['']) test('T18642', extra_run_opts('+RTS -T -RTS'), compile_and_run, ['-O2']) test('T19288', exit_code(1), compile_and_run, ['']) +test('T19719', normal, compile_and_run, ['']) |