pub fn check_ty(ctx: &Context, expr: &RcExpr, expected_ty: &RcType) -> Result<(), TypeError> {
    match *expr.inner {
        // Variant introduction
        Expr::Intro(_, ref variant_name, ref expr) => {
            // FIXME: Kindcheck union_ty
            match expected_ty.lookup_host_variant(variant_name).cloned() {
                Some(variant_ty) => {
                    check_ty(ctx, expr, &variant_ty)?;
                    Ok(())
                }
                None => Err(TypeError::MissingVariant {
                    span: ByteSpan::default(), // TODO: expr.span(),
                    union_ty: expected_ty.clone(),
                    variant_name: variant_name.clone(),
                }),
            }
        }

        // Empty arrays
        Expr::Array(_, ref elems) => match *expected_ty.inner {
            Type::HostArray(ref elem_ty) => elems
                .iter()
                .map(|elem| check_ty(ctx, elem, elem_ty))
                .collect(),
            _ => unimplemented!(), // FIXME
        },

        // Inferrable expressions
        _ => {
            let inferred_ty = infer_ty(ctx, expr)?;
            if &inferred_ty == expected_ty {
                Ok(())
            } else {
                Err(TypeError::Mismatch {
                    span: ByteSpan::default(), // TODO: expr.span(),
                    expected: expected_ty.clone(),
                    found: inferred_ty,
                })
            }
        }
    }
}
/// Check that an expression has the given type in the context
Check that an expression has the given type in the context
Check that an expression has the given type in the context
pub fn check_ty(ctx: &Context, expr: &RcExpr, expected_ty: &RcType) -> Result<(), TypeError> {
    match *expr.inner {
        // Variant introduction
        Expr::Intro(_, ref variant_name, ref expr) => {
            // FIXME: Kindcheck union_ty
            match expected_ty.lookup_host_variant(variant_name).cloned() {
                Some(variant_ty) => {
                    check_ty(ctx, expr, &variant_ty)?;
                    Ok(())
                }
                None => Err(TypeError::MissingVariant {
                    span: ByteSpan::default(), // TODO: expr.span(),
                    union_ty: expected_ty.clone(),
                    variant_name: variant_name.clone(),
                }),
            }
        }
        // Empty arrays
        Expr::Array(_, ref elems) => match *expected_ty.inner {
            Type::HostArray(ref elem_ty) => elems
                .iter()
                .map(|elem| check_ty(ctx, elem, elem_ty))
                .collect(),
            _ => unimplemented!(), // FIXME
        },
        // Inferrable expressions
        _ => {
            let inferred_ty = infer_ty(ctx, expr)?;
            if &inferred_ty == expected_ty {
                Ok(())
            } else {
                Err(TypeError::Mismatch {
                    span: ByteSpan::default(), // TODO: expr.span(),
                    expected: expected_ty.clone(),
                    found: inferred_ty,
                })
            }
        }
    }
}
pub fn check_ty ( ctx : & Context , expr : & RcExpr , expected_ty : & RcType ) -> Result < ( ) , TypeError > { match * expr . inner { // Variant introduction Expr :: Intro ( _ , ref variant_name , ref expr ) => { // FIXME: Kindcheck union_ty match expected_ty . lookup_host_variant ( variant_name ) . cloned ( ) { Some ( variant_ty ) => { check_ty ( ctx , expr , & variant_ty ) ? ; Ok ( ( ) ) } None => Err ( TypeError :: MissingVariant { span : ByteSpan :: default ( ) , // TODO: expr.span(), union_ty : expected_ty . clone ( ) , variant_name : variant_name . clone ( ) , } ) , } } // Empty arrays Expr :: Array ( _ , ref elems ) => match * expected_ty . inner { Type :: HostArray ( ref elem_ty ) => elems . iter ( ) . map ( | elem | check_ty ( ctx , elem , elem_ty ) ) . collect ( ) , _ => unimplemented ! ( ) , // FIXME } , // Inferrable expressions _ => { let inferred_ty = infer_ty ( ctx , expr ) ? ; if & inferred_ty == expected_ty { Ok ( ( ) ) } else { Err ( TypeError :: Mismatch { span : ByteSpan :: default ( ) , // TODO: expr.span(), expected : expected_ty . clone ( ) , found : inferred_ty , } ) } } } }
Check that an expression has the given type in the context
Check that an expression has the given type in the context
ctx
&Context
expr
&RcExpr
expected_ty
&RcType
ctx
&Context
expr
&RcExpr
expected_ty
&RcType