If the parameter f maps from Chars that fit in a single Word16 to Chars that require two Word16s, it is possible to write to an out-of-bounds index, as demonstrated by the following code:
module Main where
import qualified Data.Text as T
main = do
let f a c = (a, chr 65536)
print . T.mapAccumL f 0 . T.pack $ "aaaaa"
If you run this code with -DASSERTS you'll get an exception. The source of the issue is that in the inner loop of Data.Text.Fusion.mapAccumL, you determine the safety of writing into the array based on the Char passed to f instead of the one it returns.
fix mapAccumL when `f` maps Chars that fit in a single Word16 to Char…
…s that require two
Nice catch, thanks.