E4163

E4163#

Local parameters are not local.

#locals is an attribute that aims to inline the given function parameter. This error is raised when the given parameter is not a ‘local’ one.

错误示例#

///|
#locals(f)
pub fn[A] map_inline(arr : ArrayView[A], f : (A) -> A) -> Unit {
  match arr {
    [hd, .. tl] => {
      arr[0] = f(hd)
      map_inline(tl, f) // The parameter is not local: it escapes.
    }
    [] => ()
  }
}

建议#

Apply locals to local functions only.

///|
#locals(f)
pub fn[A] map_inline(arr : ArrayView[A], f : (A) -> A) -> Unit {
  for i = 0; i < arr.length(); i = i + 1 {
    arr[i] = f(arr[i])
  }
}