use crate::descriptor::FunctionDescriptor;
use crate::error::{err, index, ErrorCode, Result};
use crate::lexical;
pub fn check_define(name: &str, descriptor_json: &[u8]) -> Result<FunctionDescriptor> {
lexical::check_function_name(name, "$.name")?;
let descriptor = FunctionDescriptor::from_json(descriptor_json)?;
if !lexical::is_unrooted(name) {
if let Some(i) = descriptor.inputs.iter().position(|input| lexical::is_unrooted(input)) {
return err(
ErrorCode::UnrootedInput,
&index("$.inputs", i),
format!("the rooted function {name:?} reads the unrooted function {:?}", descriptor.inputs[i]),
);
}
}
Ok(descriptor)
}