fix: make snapshot stable (#283)

* fix: make snapshot stable

* >_<
This commit is contained in:
Myriad-Dreamin 2024-05-14 18:38:02 +08:00 committed by GitHub
parent 04dd06313a
commit 8cbd32c724
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 16 additions and 2 deletions

View file

@ -63,7 +63,7 @@ mod type_check_tests {
.map(|e| (e.1.name(), e.1))
.collect::<Vec<_>>();
vars.sort_by(|x, y| x.0.cmp(&y.0));
vars.sort_by(|x, y| x.1.var.cmp(&y.1.var));
for (name, var) in vars {
writeln!(f, "{:?} = {:?}", name, info.simplify(var.as_type(), true))?;

View file

@ -6,8 +6,8 @@ input_file: crates/tinymist-query/src/fixtures/type_check/confusing-name.typ
"date" = Any
"info" = Any
"master-cover" = (Any, "x": Any) => TypeBinary { operands: (Any, TypeBinary { operands: ({"submit-date": 0}, Any), op: Add }), op: Assign }
"x" = Any
"x" = (Any) => Any
"x" = Any
---
5..6 -> @x
7..11 -> @date

View file

@ -264,6 +264,20 @@ pub struct TypeVar {
pub syntax: Option<Interned<TypeSource>>,
}
impl Ord for TypeVar {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.name
.cmp(&other.name)
.then_with(|| self.def.0.cmp(&other.def.0))
}
}
impl PartialOrd for TypeVar {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl fmt::Debug for TypeVar {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "@{}", self.name)