Confusing type error when setting an arrays item

I’m implementing a simple lowpass filter.

open Belt

let lowpass_filter = (data, window_size) => {
  let len = data->Array.length
  let result = Array.make(len, 0.0)
  for i in 0 to len - 1 {
    let start = max(0, i - window_size / 2)
    let end = min(len, i + window_size / 2 + 1)
    let l = end - start
    let slice = data->Array.slice(~offset=start, ~len=l)
    let sum = slice->Array.reduce(0.0, (s, v) => s +. v)
    let value = sum /. l->Int.toFloat
    result[i] = value

But this result in a type error which claims the result[i] = value is an expression of type bool.

Is this a bug?

It seems that arr[i] = value is compiled to Array.set(arr, i, value). Since Belt is open, this maps to Belt.Array.set, which returns false if i is out of bounds. Since this is the last expression in the for block, the compiler complains that the whole block evaluates to bool where it, of course, expects unit (the whole for block should be basically a side effect).

TLDR: Ignoring the return value of set like this should fix it: let _ = result[i] = value