pub fn check(
    context: &Context,
    metas: &meta::Env,
    kind: LiteralKind,
    src: &SpannedString<'_>,
    expected_ty: &Rc<domain::Type>,
) -> Result<LiteralIntro, Diagnostic<FileSpan>> {
    use mltt_concrete::LiteralKind as LitKind;
    use mltt_core::domain::Value::LiteralType;
    use mltt_core::literal::{LiteralIntro as LitIntro, LiteralType as LitType};

    match (kind, expected_ty.as_ref()) {
        (LitKind::String, LiteralType(LitType::String)) => {
            parse_string(src).map(Rc::from).map(LitIntro::String)
        },
        (LitKind::Char, LiteralType(LitType::Char)) => parse_char(src).map(LitIntro::Char),
        (LitKind::Int, LiteralType(LitType::U8)) => parse_int::<u8>(src).map(LitIntro::U8),
        (LitKind::Int, LiteralType(LitType::U16)) => parse_int::<u16>(src).map(LitIntro::U16),
        (LitKind::Int, LiteralType(LitType::U32)) => parse_int::<u32>(src).map(LitIntro::U32),
        (LitKind::Int, LiteralType(LitType::U64)) => parse_int::<u64>(src).map(LitIntro::U64),
        (LitKind::Int, LiteralType(LitType::S8)) => parse_int::<i8>(src).map(LitIntro::S8),
        (LitKind::Int, LiteralType(LitType::S16)) => parse_int::<i16>(src).map(LitIntro::S16),
        (LitKind::Int, LiteralType(LitType::S32)) => parse_int::<i32>(src).map(LitIntro::S32),
        (LitKind::Int, LiteralType(LitType::S64)) => parse_int::<i64>(src).map(LitIntro::S64),
        (LitKind::Float, LiteralType(LitType::F32)) => parse_float::<f32>(src).map(LitIntro::F32),
        (LitKind::Float, LiteralType(LitType::F64)) => parse_float::<f64>(src).map(LitIntro::F64),
        (_, _) => Err(Diagnostic::new_error("mismatched literal").with_label(
            DiagnosticLabel::new_primary(src.span()).with_message(format!(
                "expected: {}",
                context
                    .value_to_doc(metas, &expected_ty)
                    .pretty(1000_000_000),
            )),
        )),
    }
}
/// Check the type of a literal in a context.
Check the type of a literal in a context.
Check the type of a literal in a context .
pub fn check(
    context: &Context,
    metas: &meta::Env,
    kind: LiteralKind,
    src: &SpannedString<'_>,
    expected_ty: &Rc<domain::Type>,
) -> Result<LiteralIntro, Diagnostic<FileSpan>> {
    use mltt_concrete::LiteralKind as LitKind;
    use mltt_core::domain::Value::LiteralType;
    use mltt_core::literal::{LiteralIntro as LitIntro, LiteralType as LitType};
    match (kind, expected_ty.as_ref()) {
        (LitKind::String, LiteralType(LitType::String)) => {
            parse_string(src).map(Rc::from).map(LitIntro::String)
        },
        (LitKind::Char, LiteralType(LitType::Char)) => parse_char(src).map(LitIntro::Char),
        (LitKind::Int, LiteralType(LitType::U8)) => parse_int::<u8>(src).map(LitIntro::U8),
        (LitKind::Int, LiteralType(LitType::U16)) => parse_int::<u16>(src).map(LitIntro::U16),
        (LitKind::Int, LiteralType(LitType::U32)) => parse_int::<u32>(src).map(LitIntro::U32),
        (LitKind::Int, LiteralType(LitType::U64)) => parse_int::<u64>(src).map(LitIntro::U64),
        (LitKind::Int, LiteralType(LitType::S8)) => parse_int::<i8>(src).map(LitIntro::S8),
        (LitKind::Int, LiteralType(LitType::S16)) => parse_int::<i16>(src).map(LitIntro::S16),
        (LitKind::Int, LiteralType(LitType::S32)) => parse_int::<i32>(src).map(LitIntro::S32),
        (LitKind::Int, LiteralType(LitType::S64)) => parse_int::<i64>(src).map(LitIntro::S64),
        (LitKind::Float, LiteralType(LitType::F32)) => parse_float::<f32>(src).map(LitIntro::F32),
        (LitKind::Float, LiteralType(LitType::F64)) => parse_float::<f64>(src).map(LitIntro::F64),
        (_, _) => Err(Diagnostic::new_error("mismatched literal").with_label(
            DiagnosticLabel::new_primary(src.span()).with_message(format!(
                "expected: {}",
                context
                    .value_to_doc(metas, &expected_ty)
                    .pretty(1000_000_000),
            )),
        )),
    }
}
pub fn check ( context : & Context , metas : & meta :: Env , kind : LiteralKind , src : & SpannedString < ' _ > , expected_ty : & Rc < domain :: Type > , ) -> Result < LiteralIntro , Diagnostic < FileSpan > > { use mltt_concrete :: LiteralKind as LitKind ; use mltt_core :: domain :: Value :: LiteralType ; use mltt_core :: literal :: { LiteralIntro as LitIntro , LiteralType as LitType } ; match ( kind , expected_ty . as_ref ( ) ) { ( LitKind :: String , LiteralType ( LitType :: String ) ) => { parse_string ( src ) . map ( Rc :: from ) . map ( LitIntro :: String ) } , ( LitKind :: Char , LiteralType ( LitType :: Char ) ) => parse_char ( src ) . map ( LitIntro :: Char ) , ( LitKind :: Int , LiteralType ( LitType :: U8 ) ) => parse_int :: < u8 > ( src ) . map ( LitIntro :: U8 ) , ( LitKind :: Int , LiteralType ( LitType :: U16 ) ) => parse_int :: < u16 > ( src ) . map ( LitIntro :: U16 ) , ( LitKind :: Int , LiteralType ( LitType :: U32 ) ) => parse_int :: < u32 > ( src ) . map ( LitIntro :: U32 ) , ( LitKind :: Int , LiteralType ( LitType :: U64 ) ) => parse_int :: < u64 > ( src ) . map ( LitIntro :: U64 ) , ( LitKind :: Int , LiteralType ( LitType :: S8 ) ) => parse_int :: < i8 > ( src ) . map ( LitIntro :: S8 ) , ( LitKind :: Int , LiteralType ( LitType :: S16 ) ) => parse_int :: < i16 > ( src ) . map ( LitIntro :: S16 ) , ( LitKind :: Int , LiteralType ( LitType :: S32 ) ) => parse_int :: < i32 > ( src ) . map ( LitIntro :: S32 ) , ( LitKind :: Int , LiteralType ( LitType :: S64 ) ) => parse_int :: < i64 > ( src ) . map ( LitIntro :: S64 ) , ( LitKind :: Float , LiteralType ( LitType :: F32 ) ) => parse_float :: < f32 > ( src ) . map ( LitIntro :: F32 ) , ( LitKind :: Float , LiteralType ( LitType :: F64 ) ) => parse_float :: < f64 > ( src ) . map ( LitIntro :: F64 ) , ( _ , _ ) => Err ( Diagnostic :: new_error ( " " ) . with_label ( DiagnosticLabel :: new_primary ( src . span ( ) ) . with_message ( format ! ( " " context value_to_doc ( metas expected_ty ) pretty ( 1000_000_000 ) ) ) , ) ) , } }
Check the type of a literal in a context.
Check the type of a literal in a context .
context
&Context
metas
&meta::Env
kind
LiteralKind
src
&SpannedString<'_>
expected_ty
&Rc<domain::Type>
context
&Context
metas
&meta::Env
kind
LiteralKind
src
&SpannedString<'_>
expected_ty
&Rc<domain::Type>