E4162

E4162#

Local parameter is not function.

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

错误示例#

///|
#locals(init_)
pub fn[A, B] fold(a : Array[A], init_~ : B, f : (B, A) -> B) -> B {
  //                            ^
  // This parameter is expected to be a function, but it is not.
  let mut acc = init_
  for x in a {
    acc = f(acc, x)
  }
  acc
}

建议#

Apply locals to local functions only.

///|
#locals(f)
pub fn[A, B] fold(a : Array[A], init_~ : B, f : (B, A) -> B) -> B {
  let mut acc = init_
  for x in a {
    acc = f(acc, x)
  }
  acc
}