feat: simple lint types comparing with strings (#1643)

* feat: simple lint types comparing with strings

* dev: edit message

* fix: message
This commit is contained in:
Myriad-Dreamin 2025-04-10 20:02:56 +08:00 committed by GitHub
parent 23f10a2648
commit 4265bc25bc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 170 additions and 13 deletions

View file

@ -248,12 +248,49 @@ impl Ty {
});
res
}
pub fn is_str<T: TyCtx>(&self, ctx: &T) -> bool {
let mut res = false;
self.satisfy(ctx, |ty: &Ty, _pol| {
res = res || {
match ty {
Ty::Value(v) => is_str_builtin_type(&v.val.ty()),
Ty::Builtin(BuiltinTy::Type(v)) => is_str_builtin_type(v),
_ => false,
}
}
});
res
}
pub fn is_type<T: TyCtx>(&self, ctx: &T) -> bool {
let mut res = false;
self.satisfy(ctx, |ty: &Ty, _pol| {
res = res || {
match ty {
Ty::Value(v) => is_type_builtin_type(&v.val.ty()),
Ty::Builtin(BuiltinTy::Type(ty)) => is_type_builtin_type(ty),
Ty::Builtin(BuiltinTy::TypeType(..)) => true,
_ => false,
}
}
});
res
}
}
fn is_content_builtin_type(ty: &Type) -> bool {
*ty == Type::of::<Content>() || *ty == Type::of::<typst::foundations::Symbol>()
}
fn is_str_builtin_type(ty: &Type) -> bool {
*ty == Type::of::<typst::foundations::Str>()
}
fn is_type_builtin_type(ty: &Type) -> bool {
*ty == Type::of::<Type>()
}
/// A function parameter type
pub enum TypeSigParam<'a> {
/// A positional parameter
@ -1195,6 +1232,14 @@ pub struct TypeInfo {
pub(super) cano_cache: Mutex<TypeCanoStore>,
}
impl Hash for TypeInfo {
fn hash<H: Hasher>(&self, state: &mut H) {
self.valid.hash(state);
self.fid.hash(state);
self.revision.hash(state);
}
}
impl TyCtx for TypeInfo {
fn global_bounds(&self, var: &Interned<TypeVar>, _pol: bool) -> Option<DynTypeBounds> {
let v = self.vars.get(&var.def)?;