diff --git a/crates/tinymist-query/src/analysis.rs b/crates/tinymist-query/src/analysis.rs index 81977f86..c20c17d9 100644 --- a/crates/tinymist-query/src/analysis.rs +++ b/crates/tinymist-query/src/analysis.rs @@ -63,7 +63,7 @@ mod type_check_tests { .map(|e| (e.1.name(), e.1)) .collect::>(); - 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))?; diff --git a/crates/tinymist-query/src/fixtures/type_check/snaps/test@confusing-name.typ.snap b/crates/tinymist-query/src/fixtures/type_check/snaps/test@confusing-name.typ.snap index 1794486b..4b762250 100644 --- a/crates/tinymist-query/src/fixtures/type_check/snaps/test@confusing-name.typ.snap +++ b/crates/tinymist-query/src/fixtures/type_check/snaps/test@confusing-name.typ.snap @@ -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 diff --git a/crates/tinymist-query/src/ty/def.rs b/crates/tinymist-query/src/ty/def.rs index be9e4d5d..e54127fa 100644 --- a/crates/tinymist-query/src/ty/def.rs +++ b/crates/tinymist-query/src/ty/def.rs @@ -264,6 +264,20 @@ pub struct TypeVar { pub syntax: Option>, } +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 { + Some(self.cmp(other)) + } +} + impl fmt::Debug for TypeVar { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "@{}", self.name)