summaryrefslogtreecommitdiff
path: root/testsuite/tests
diff options
context:
space:
mode:
authorIavor Diatchki <iavor.diatchki@gmail.com>2019-05-07 13:02:27 -0700
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-05-23 22:39:35 -0400
commit59f4cb6fb73ade6f9b0bdc85380dfddba93bf14b (patch)
tree8ab925cad228682295170df9208856fc33b9f3b8 /testsuite/tests
parent0b449d3415543771779a74f8d867eb1a4748ddb2 (diff)
downloadhaskell-59f4cb6fb73ade6f9b0bdc85380dfddba93bf14b.tar.gz
Add a `NOINLINE` pragma on `someNatVal` (#16586)
This fixes #16586, see `Note [NOINLINE someNatVal]` for details.
Diffstat (limited to 'testsuite/tests')
-rw-r--r--testsuite/tests/lib/base/T16586.hs27
-rw-r--r--testsuite/tests/lib/base/T16586.stdout1
-rw-r--r--testsuite/tests/lib/base/all.T1
3 files changed, 29 insertions, 0 deletions
diff --git a/testsuite/tests/lib/base/T16586.hs b/testsuite/tests/lib/base/T16586.hs
new file mode 100644
index 0000000000..37169e650a
--- /dev/null
+++ b/testsuite/tests/lib/base/T16586.hs
@@ -0,0 +1,27 @@
+{-# LANGUAGE DataKinds, PolyKinds, RankNTypes, ScopedTypeVariables #-}
+
+module Main where
+
+import Data.Proxy
+import GHC.TypeNats
+import Numeric.Natural
+
+newtype Foo (m :: Nat) = Foo { getVal :: Word }
+
+mul :: KnownNat m => Foo m -> Foo m -> Foo m
+mul mx@(Foo x) (Foo y) =
+ Foo $ x * y `rem` fromIntegral (natVal mx)
+
+pow :: KnownNat m => Foo m -> Int -> Foo m
+pow x k = iterate (`mul` x) (Foo 1) !! k
+
+modl :: (forall m. KnownNat m => Foo m) -> Natural -> Word
+modl x m = case someNatVal m of
+ SomeNat (_ :: Proxy m) -> getVal (x :: Foo m)
+
+-- Should print 1
+main :: IO ()
+main = print $ (Foo 127 `pow` 31336) `modl` 31337
+
+dummyValue :: Word
+dummyValue = (Foo 33 `pow` 44) `modl` 456
diff --git a/testsuite/tests/lib/base/T16586.stdout b/testsuite/tests/lib/base/T16586.stdout
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/testsuite/tests/lib/base/T16586.stdout
@@ -0,0 +1 @@
+1
diff --git a/testsuite/tests/lib/base/all.T b/testsuite/tests/lib/base/all.T
new file mode 100644
index 0000000000..ff0c9f963f
--- /dev/null
+++ b/testsuite/tests/lib/base/all.T
@@ -0,0 +1 @@
+test('T16586', normal, compile_and_run, ['-O2'])