MCPcopy Create free account
hub / github.com/amber-lang/amber / handle_add_function

Function handle_add_function

src/modules/function/declaration_utils.rs:79–104  ·  view source on GitHub ↗
(
    meta: &mut ParserMetadata,
    tok: Option<Token>,
    fun: FunctionInterface,
    ctx: Context,
    block: Block,
)

Source from the content-addressed store, hash-verified

77}
78
79pub 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}

Callers 1

typecheckMethod · 0.85

Calls 2

handle_identifier_nameFunction · 0.85
add_fun_declarationMethod · 0.80

Tested by

no test coverage detected