@@ -455,7 +455,10 @@ byteLength Array{..} =
455455-- @since 0.7.0
456456{-# INLINE length #-}
457457length :: forall a. Storable a => Array a -> Int
458−length arr = byteLength arr `div` sizeOf (undefined :: a)
458+length arr =
459+ let elemSize = sizeOf (undefined :: a)
460+ blen = byteLength arr
461+ in assert (blen `mod` elemSize == 0) (blen `div` elemSize)
459462
460463-- | Get the total capacity of an array. An array may have space reserved
461464-- beyond the current used length of the array.