UArray Bool can perform "out-of-bounds" reads
Summary
Compile the following program with ghc -fcheck-prim-bounds -O Main.hs
.
module Main (main) where
import Data.Array.Unboxed
arr :: UArray Int Bool
arr = listArray (2,7) (map even [2..7])
main :: IO ()
main = print (arr ! 5)
When run, it crashes with an error message like this one:
Main: internal error: Encountered out of bounds array access.
(GHC version 9.4.4 for x86_64_unknown_linux)
Please report this as a GHC bug: https://www.haskell.org/ghc/reportabug
Aborted
Expected behavior
This is an in-bounds UArray
access; the array
library should correctly lower it to an in-bounds ByteArray#
access.
Diagnosis: The basic problem is that the UArray i Bool
stuff rounds the size of the underlying buffer to the nearest byte but actually does reads and writes at machine-word width.