Handle generic args per arg index

Add more test cases for generic args
This commit is contained in:
Hongxu Xu 2022-07-07 00:43:59 +08:00
parent 0f2eba54db
commit 75fb3de310
4 changed files with 220 additions and 45 deletions

View file

@ -47,6 +47,7 @@ pub struct LifetimeParamData {
pub struct ConstParamData {
pub name: Name,
pub ty: Interned<TypeRef>,
pub has_default: bool,
}
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
@ -70,6 +71,13 @@ impl TypeOrConstParamData {
}
}
pub fn has_default(&self) -> bool {
match self {
TypeOrConstParamData::TypeParamData(x) => x.default.is_some(),
TypeOrConstParamData::ConstParamData(x) => x.has_default,
}
}
pub fn type_param(&self) -> Option<&TypeParamData> {
match self {
TypeOrConstParamData::TypeParamData(x) => Some(x),
@ -232,7 +240,11 @@ impl GenericParams {
let ty = const_param
.ty()
.map_or(TypeRef::Error, |it| TypeRef::from_ast(lower_ctx, it));
let param = ConstParamData { name, ty: Interned::new(ty) };
let param = ConstParamData {
name,
ty: Interned::new(ty),
has_default: const_param.default_val().is_some(),
};
self.type_or_consts.alloc(param.into());
}
}