11{-# LANGUAGE CPP #-}
22{-# LANGUAGE MagicHash #-}
33{-# LANGUAGE ScopedTypeVariables #-}
4+ {-# LANGUAGE TypeApplications #-}
45{-# LANGUAGE UnboxedTuples #-}
56module Regressions (tests ) where
67
@@ -11,6 +12,7 @@ import Data.List (delete)
1112import Data.Maybe (isJust , isNothing )
1213import GHC.Exts (touch #)
1314import GHC.IO (IO (.. ))
15+ import Numeric.Natural (Natural )
1416import System.Mem (performGC )
1517import System.Mem.Weak (deRefWeak , mkWeakPtr )
1618import System.Random (randomIO )
@@ -225,6 +227,27 @@ issue382 = do
225227 touch v -- makes sure that we didn't GC away the combined value
226228 assert $ isNothing res
227229
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+
228251------------------------------------------------------------------------
229252-- * Test list
230253
@@ -251,4 +274,7 @@ tests = testGroup "Regression tests"
251274 ]
252275#endif
253276 , testCase " issue382" issue382
277+ #ifdef HAVE_NOTHUNKS
278+ , testCase " issue383" issue383
279+ #endif
254280 ]
0 commit comments