Properly set the enum variant body expected type

This commit is contained in:
Lukas Wirth 2022-09-20 17:15:48 +02:00
parent 9f233cd5d2
commit b25f0ba15b

View File

@ -18,7 +18,9 @@ use std::sync::Arc;
use chalk_ir::{cast::Cast, ConstValue, DebruijnIndex, Mutability, Safety, Scalar, TypeFlags}; use chalk_ir::{cast::Cast, ConstValue, DebruijnIndex, Mutability, Safety, Scalar, TypeFlags};
use hir_def::{ use hir_def::{
adt::{ReprData, ReprKind},
body::Body, body::Body,
builtin_type::BuiltinType,
data::{ConstData, StaticData}, data::{ConstData, StaticData},
expr::{BindingAnnotation, ExprId, PatId}, expr::{BindingAnnotation, ExprId, PatId},
lang_item::LangItemTarget, lang_item::LangItemTarget,
@ -67,12 +69,16 @@ pub(crate) fn infer_query(db: &dyn HirDatabase, def: DefWithBodyId) -> Arc<Infer
DefWithBodyId::ConstId(c) => ctx.collect_const(&db.const_data(c)), DefWithBodyId::ConstId(c) => ctx.collect_const(&db.const_data(c)),
DefWithBodyId::FunctionId(f) => ctx.collect_fn(f), DefWithBodyId::FunctionId(f) => ctx.collect_fn(f),
DefWithBodyId::StaticId(s) => ctx.collect_static(&db.static_data(s)), DefWithBodyId::StaticId(s) => ctx.collect_static(&db.static_data(s)),
DefWithBodyId::VariantId(_v) => { DefWithBodyId::VariantId(v) => {
// db.enum_data(v.parent) ctx.return_ty = match db.enum_data(v.parent).repr {
// FIXME: This should return the `repr(...)` type of the enum Some(ReprData { kind: ReprKind::BuiltinInt { builtin, .. }, .. }) => {
ctx.return_ty = TyBuilder::builtin(hir_def::builtin_type::BuiltinType::Uint( TyBuilder::builtin(match builtin {
hir_def::builtin_type::BuiltinUint::U32, Either::Left(builtin) => BuiltinType::Int(builtin),
)); Either::Right(builtin) => BuiltinType::Uint(builtin),
})
}
_ => TyBuilder::builtin(BuiltinType::Uint(hir_def::builtin_type::BuiltinUint::U32)),
};
} }
} }