pub fn check_clause(
    context: &Context,
    metas: &mut meta::Env,
    mut clause: Clause<'_>,
    expected_ty: &Rc<domain::Type>,
) -> Result<Rc<syntax::Term>, Diagnostic<FileSpan>> {
    let mut context = context.clone();
    let mut params = Vec::new();
    let mut expected_ty = expected_ty.clone();

    while let (Some((app_mode, param_ty, next_body_ty)), Some((head_param, rest_params))) = (
        next_expected_param(&expected_ty),
        clause.params.split_first(),
    ) {
        let (param_var, name_hint) = match check_param_app_mode(head_param, &app_mode)? {
            CheckedPattern::Var(None) => (context.add_fresh_param(param_ty), None),
            CheckedPattern::Var(Some(var_name)) => {
                clause.params = rest_params;
                (
                    context.add_param(var_name, param_ty),
                    Some(var_name.to_string()),
                )
            },
            CheckedPattern::LiteralIntro(_, literal) => {
                return Err(Diagnostic::new_error("non-exhaustive patterns").with_label(
                    DiagnosticLabel::new_primary(literal.span())
                        .with_message("use a case expression for matching on literals"),
                ));
            },
        };

        params.push((app_mode, name_hint));
        expected_ty = context.app_closure(metas, next_body_ty, param_var)?;
    }

    let body = check_clause_body(&context, metas, &clause, &expected_ty)?;

    Ok(done(Vec::new(), params, body))
}
/// Check that a given clause conforms to an expected type, and elaborates
/// it into a case tree.
///
/// Returns the elaborated term.
Check that a given clause conforms to an expected type, and elaborates
it into a case tree.

Returns the elaborated term.
Check that a given clause conforms to an expected type and elaborates it into a case tree . Returns the elaborated term .
pub fn check_clause(
    context: &Context,
    metas: &mut meta::Env,
    mut clause: Clause<'_>,
    expected_ty: &Rc<domain::Type>,
) -> Result<Rc<syntax::Term>, Diagnostic<FileSpan>> {
    let mut context = context.clone();
    let mut params = Vec::new();
    let mut expected_ty = expected_ty.clone();
    while let (Some((app_mode, param_ty, next_body_ty)), Some((head_param, rest_params))) = (
        next_expected_param(&expected_ty),
        clause.params.split_first(),
    ) {
        let (param_var, name_hint) = match check_param_app_mode(head_param, &app_mode)? {
            CheckedPattern::Var(None) => (context.add_fresh_param(param_ty), None),
            CheckedPattern::Var(Some(var_name)) => {
                clause.params = rest_params;
                (
                    context.add_param(var_name, param_ty),
                    Some(var_name.to_string()),
                )
            },
            CheckedPattern::LiteralIntro(_, literal) => {
                return Err(Diagnostic::new_error("non-exhaustive patterns").with_label(
                    DiagnosticLabel::new_primary(literal.span())
                        .with_message("use a case expression for matching on literals"),
                ));
            },
        };
        params.push((app_mode, name_hint));
        expected_ty = context.app_closure(metas, next_body_ty, param_var)?;
    }
    let body = check_clause_body(&context, metas, &clause, &expected_ty)?;
    Ok(done(Vec::new(), params, body))
}
pub fn check_clause ( context : & Context , metas : & mut meta :: Env , mut clause : Clause < ' _ > , expected_ty : & Rc < domain :: Type > , ) -> Result < Rc < syntax :: Term > , Diagnostic < FileSpan > > { let mut context = context . clone ( ) ; let mut params = Vec :: new ( ) ; let mut expected_ty = expected_ty . clone ( ) ; while let ( Some ( ( app_mode , param_ty , next_body_ty ) ) , Some ( ( head_param , rest_params ) ) ) = ( next_expected_param ( & expected_ty ) , clause . params . split_first ( ) , ) { let ( param_var , name_hint ) = match check_param_app_mode ( head_param , & app_mode ) ? { CheckedPattern :: Var ( None ) => ( context . add_fresh_param ( param_ty ) , None ) , CheckedPattern :: Var ( Some ( var_name ) ) => { clause . params = rest_params ; ( context . add_param ( var_name , param_ty ) , Some ( var_name . to_string ( ) ) , ) } , CheckedPattern :: LiteralIntro ( _ , literal ) => { return Err ( Diagnostic :: new_error ( " " ) . with_label ( DiagnosticLabel :: new_primary ( literal . span ( ) ) . with_message ( " " ) , ) ) ; } , } ; params . push ( ( app_mode , name_hint ) ) ; expected_ty = context . app_closure ( metas , next_body_ty , param_var ) ? ; } let body = check_clause_body ( & context , metas , & clause , & expected_ty ) ? ; Ok ( done ( Vec :: new ( ) , params , body ) ) }
Check that a given clause conforms to an expected type, and elaborates
it into a case tree.
Check that a given clause conforms to an expected type and elaborates it into a case tree .
context
&Context
metas
&mut meta::Env
clause
Clause<'_>
expected_ty
&Rc<domain::Type>
context
&Context
metas
&mut meta::Env
clause
Clause<'_>
expected_ty
&Rc<domain::Type>