Fix for built-in Natural literals desugaring
authorSylvain Henry <hsyl20@gmail.com>
Fri, 6 Jul 2018 15:01:14 +0000 (11:01 -0400)
committerBen Gamari <ben@smart-cactus.org>
Fri, 6 Jul 2018 18:08:37 +0000 (14:08 -0400)
The recent patch "Built-in Natural literals in Core"
(https://phabricator.haskell.org/rGHCfe770c211631e7b4c9b0b1e88ef9b6046c6
585ef) introduced a regression when desugaring large numbers.

This patch fixes it and adds a regression test.

Reviewers: hvr, bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #15301

Differential Revision: https://phabricator.haskell.org/D4885

libraries/base/GHC/Natural.hs
testsuite/tests/numeric/should_run/T15301.hs [new file with mode: 0644]
testsuite/tests/numeric/should_run/T15301.stdout [new file with mode: 0644]
testsuite/tests/numeric/should_run/all.T

index db8d8b8..a35688d 100644 (file)
@@ -594,7 +594,7 @@ mkNatural :: [Word]  -- ^ value expressed in 32 bit chunks, least
           -> Natural
 mkNatural [] = wordToNaturalBase 0##
 mkNatural (W# i : is') = wordToNaturalBase (i `and#` 0xffffffff##) `orNatural`
-                         shiftLNatural (mkNatural is') 31
+                         shiftLNatural (mkNatural is') 32
 {-# CONSTANT_FOLDED mkNatural #-}
 
 -- | Convert 'Int' to 'Natural'.
diff --git a/testsuite/tests/numeric/should_run/T15301.hs b/testsuite/tests/numeric/should_run/T15301.hs
new file mode 100644 (file)
index 0000000..6efbce4
--- /dev/null
@@ -0,0 +1,7 @@
+import Numeric
+import GHC.Natural
+
+main = do
+   -- test that GHC correctly compiles big Natural literals
+   let x = 0xffffffffffffffffffffffff :: Natural
+   print (showHex x "" == "ffffffffffffffffffffffff")
diff --git a/testsuite/tests/numeric/should_run/T15301.stdout b/testsuite/tests/numeric/should_run/T15301.stdout
new file mode 100644 (file)
index 0000000..0ca9514
--- /dev/null
@@ -0,0 +1 @@
+True
index 691fc26..140fa6c 100644 (file)
@@ -65,3 +65,4 @@ test('T10011', normal, compile_and_run, [''])
 test('T10962', omit_ways(['ghci']), compile_and_run, ['-O2'])
 test('T11702', extra_ways(['optasm']), compile_and_run, [''])
 test('T12136', normal, compile_and_run, [''])
+test('T15301', normal, compile_and_run, ['-O2'])