mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-11-25 13:23:44 +00:00
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:
parent
23f10a2648
commit
4265bc25bc
10 changed files with 170 additions and 13 deletions
|
|
@ -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)?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue