(
meta: &mut ParserMetadata,
tok: Option<Token>,
fun: FunctionInterface,
ctx: Context,
block: Block,
)
| 77 | } |
| 78 | |
| 79 | pub fn handle_add_function( |
| 80 | meta: &mut ParserMetadata, |
| 81 | tok: Option<Token>, |
| 82 | fun: FunctionInterface, |
| 83 | ctx: Context, |
| 84 | block: Block, |
| 85 | ) -> Result<usize, Failure> { |
| 86 | let name = fun.name.clone(); |
| 87 | handle_identifier_name(meta, &name, tok.clone())?; |
| 88 | let any_generic = fun.args.iter().any(|arg| arg.kind == Type::Generic); |
| 89 | let any_typed = fun.args.iter().any(|arg| arg.kind != Type::Generic); |
| 90 | // Either all arguments are generic or typed |
| 91 | if any_typed && any_generic { |
| 92 | return error!(meta, tok => { |
| 93 | message: format!("Function '{}' has a mix of generic and typed arguments", name), |
| 94 | comment: "Please decide whether to use generics or types for all arguments" |
| 95 | }); |
| 96 | } |
| 97 | // Try to add the function to the memory |
| 98 | match meta.add_fun_declaration(fun, ctx, block) { |
| 99 | // Return the id of the function |
| 100 | Some(id) => Ok(id), |
| 101 | // If the function already exists, show an error |
| 102 | None => error!(meta, tok, format!("Function '{}' already exists", name)), |
| 103 | } |
| 104 | } |
no test coverage detected