pub fn func_def(
    contract_scope: Shared<ContractScope>,
    context: Shared<Context>,
    def: &Spanned<fe::ContractStmt>,
) -> Result<(), SemanticError> {
    if let fe::ContractStmt::FuncDef {
        qual,
        name,
        args,
        return_type,
        body: _,
    } = &def.node
    {
        let name = name.node;
        let function_scope = BlockScope::from_contract_scope(name, Rc::clone(&contract_scope));

        let param_types = args
            .iter()
            .map(|arg| func_def_arg(Rc::clone(&function_scope), arg))
            .collect::<Result<Vec<_>, _>>()?;

        let return_type = return_type
            .as_ref()
            .map(|typ| types::type_desc_fixed_size(Scope::Block(Rc::clone(&function_scope)), &typ))
            .transpose()?
            .unwrap_or_else(|| Tuple::empty().into());

        let is_public = qual.is_some();
        contract_scope.borrow_mut().add_function(
            name,
            is_public,
            param_types.clone(),
            return_type.clone(),
            Rc::clone(&function_scope),
        )?;

        let attributes = FunctionAttributes {
            name: name.to_owned(),
            param_types,
            return_type,
        };

        context.borrow_mut().add_function(def, attributes);

        return Ok(());
    }

    unreachable!();
}
/// Gather context information for a function definition and check for type
/// errors. Does not inspect the function body.
Gather context information for a function definition and check for type
errors. Does not inspect the function body.
Gather context information for a function definition and check for type errors . Does not inspect the function body .
pub fn func_def(
    contract_scope: Shared<ContractScope>,
    context: Shared<Context>,
    def: &Spanned<fe::ContractStmt>,
) -> Result<(), SemanticError> {
    if let fe::ContractStmt::FuncDef {
        qual,
        name,
        args,
        return_type,
        body: _,
    } = &def.node
    {
        let name = name.node;
        let function_scope = BlockScope::from_contract_scope(name, Rc::clone(&contract_scope));
        let param_types = args
            .iter()
            .map(|arg| func_def_arg(Rc::clone(&function_scope), arg))
            .collect::<Result<Vec<_>, _>>()?;
        let return_type = return_type
            .as_ref()
            .map(|typ| types::type_desc_fixed_size(Scope::Block(Rc::clone(&function_scope)), &typ))
            .transpose()?
            .unwrap_or_else(|| Tuple::empty().into());
        let is_public = qual.is_some();
        contract_scope.borrow_mut().add_function(
            name,
            is_public,
            param_types.clone(),
            return_type.clone(),
            Rc::clone(&function_scope),
        )?;
        let attributes = FunctionAttributes {
            name: name.to_owned(),
            param_types,
            return_type,
        };
        context.borrow_mut().add_function(def, attributes);
        return Ok(());
    }
    unreachable!();
}
pub fn func_def ( contract_scope : Shared < ContractScope > , context : Shared < Context > , def : & Spanned < fe :: ContractStmt > , ) -> Result < ( ) , SemanticError > { if let fe :: ContractStmt :: FuncDef { qual , name , args , return_type , body : _ , } = & def . node { let name = name . node ; let function_scope = BlockScope :: from_contract_scope ( name , Rc :: clone ( & contract_scope ) ) ; let param_types = args . iter ( ) . map ( | arg | func_def_arg ( Rc :: clone ( & function_scope ) , arg ) ) . collect :: < Result < Vec < _ > , _ > > ( ) ? ; let return_type = return_type . as_ref ( ) . map ( | typ | types :: type_desc_fixed_size ( Scope :: Block ( Rc :: clone ( & function_scope ) ) , & typ ) ) . transpose ( ) ? . unwrap_or_else ( | | Tuple :: empty ( ) . into ( ) ) ; let is_public = qual . is_some ( ) ; contract_scope . borrow_mut ( ) . add_function ( name , is_public , param_types . clone ( ) , return_type . clone ( ) , Rc :: clone ( & function_scope ) , ) ? ; let attributes = FunctionAttributes { name : name . to_owned ( ) , param_types , return_type , } ; context . borrow_mut ( ) . add_function ( def , attributes ) ; return Ok ( ( ) ) ; } unreachable ! ( ) ; }
Gather context information for a function definition and check for type
errors.
Gather context information for a function definition and check for type errors .
contract_scope
Shared<ContractScope>
context
Shared<Context>
def
&Spanned<fe::ContractStmt>
contract_scope
Shared<ContractScope>
context
Shared<Context>
def
&Spanned<fe::ContractStmt>