1
1
{-# LANGUAGE CPP #-}
2
2
{-# LANGUAGE MagicHash #-}
3
3
{-# LANGUAGE ScopedTypeVariables #-}
4
+ {-# LANGUAGE TypeApplications #-}
4
5
{-# LANGUAGE UnboxedTuples #-}
5
6
module Regressions (tests ) where
6
7
@@ -11,6 +12,7 @@ import Data.List (delete)
11
12
import Data.Maybe (isJust , isNothing )
12
13
import GHC.Exts (touch #)
13
14
import GHC.IO (IO (.. ))
15
+ import Numeric.Natural (Natural )
14
16
import System.Mem (performGC )
15
17
import System.Mem.Weak (deRefWeak , mkWeakPtr )
16
18
import System.Random (randomIO )
@@ -225,6 +227,27 @@ issue382 = do
225
227
touch v -- makes sure that we didn't GC away the combined value
226
228
assert $ isNothing res
227
229
230
+ ------------------------------------------------------------------------
231
+ -- Issue #383
232
+
233
+ #ifdef HAVE_NOTHUNKS
234
+
235
+ -- Custom Functor to prevent interference from alterF rules
236
+ newtype MyIdentity a = MyIdentity a
237
+ instance Functor MyIdentity where
238
+ fmap f (MyIdentity x) = MyIdentity (f x)
239
+
240
+ issue383 :: Assertion
241
+ issue383 = do
242
+ i :: Int <- randomIO
243
+ let f Nothing = MyIdentity (Just (fromIntegral @ Int @ Natural (abs i)))
244
+ f Just {} = MyIdentity (error " Impossible" )
245
+ let (MyIdentity m) = HMS. alterF f () mempty
246
+ mThunkInfo <- noThunksInValues mempty (Foldable. toList m)
247
+ assert $ isNothing mThunkInfo
248
+
249
+ #endif
250
+
228
251
------------------------------------------------------------------------
229
252
-- * Test list
230
253
@@ -251,4 +274,7 @@ tests = testGroup "Regression tests"
251
274
]
252
275
#endif
253
276
, testCase " issue382" issue382
277
+ #ifdef HAVE_NOTHUNKS
278
+ , testCase " issue383" issue383
279
+ #endif
254
280
]
0 commit comments