Use explicit lazy binding around undefined in inlinable functions
Summary
undefined
in inlinable functions are unintentionally evaluated if called strictly. An example:
{-# INLINE alloca #-}
alloca :: forall a b . Storable a => (Ptr a -> IO b) -> IO b
alloca =
allocaBytesAligned (sizeOf (undefined :: a)) (alignment (undefined :: a))
Steps to reproduce
Use Foreign.Marshal.Alloc.alloca
with Strict
language extension.
Expected behavior
It should allocate a memory, not evaluating undefined
. If undefined
s are used in inlinable functions, lazy bindings must be used explicitly for GHC 8.0 or later.
Environment
- GHC version used: 8.0 or later
Optional: