From b0c71a0961e15a09155f300f0199d76cf710e502 Mon Sep 17 00:00:00 2001 From: Myriad-Dreamin <35292584+Myriad-Dreamin@users.noreply.github.com> Date: Tue, 7 May 2024 13:39:04 +0800 Subject: [PATCH] fix: infinite loop in simplifying recursive functions (#246) * fix: infinite loop in simplifying recursive functions * dev: update snapshot --- crates/tinymist-query/src/analysis/ty.rs | 9 ++++++--- .../src/fixtures/type_check/recursive.typ | 5 +++++ .../fixtures/type_check/snaps/test@recursive.typ.snap | 11 +++++++++++ tests/e2e/main.rs | 2 +- 4 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 crates/tinymist-query/src/fixtures/type_check/recursive.typ create mode 100644 crates/tinymist-query/src/fixtures/type_check/snaps/test@recursive.typ.snap diff --git a/crates/tinymist-query/src/analysis/ty.rs b/crates/tinymist-query/src/analysis/ty.rs index 29613aa4..c7dd818d 100644 --- a/crates/tinymist-query/src/analysis/ty.rs +++ b/crates/tinymist-query/src/analysis/ty.rs @@ -1457,10 +1457,13 @@ impl<'a, 'b> TypeSimplifier<'a, 'b> { match &w.kind { FlowVarKind::Weak(w) => { let w = w.read(); - if pol { - self.positives.insert(v.0); + let inserted = if pol { + self.positives.insert(v.0) } else { - self.negatives.insert(v.0); + self.negatives.insert(v.0) + }; + if !inserted { + return; } if pol { diff --git a/crates/tinymist-query/src/fixtures/type_check/recursive.typ b/crates/tinymist-query/src/fixtures/type_check/recursive.typ new file mode 100644 index 00000000..fecf0b28 --- /dev/null +++ b/crates/tinymist-query/src/fixtures/type_check/recursive.typ @@ -0,0 +1,5 @@ +// path: base.typ +#let a(x) = a; +----- +#import "base.typ": * +#let f() = a() \ No newline at end of file diff --git a/crates/tinymist-query/src/fixtures/type_check/snaps/test@recursive.typ.snap b/crates/tinymist-query/src/fixtures/type_check/snaps/test@recursive.typ.snap new file mode 100644 index 00000000..d37a6343 --- /dev/null +++ b/crates/tinymist-query/src/fixtures/type_check/snaps/test@recursive.typ.snap @@ -0,0 +1,11 @@ +--- +source: crates/tinymist-query/src/analysis.rs +expression: result +input_file: crates/tinymist-query/src/fixtures/type_check/recursive.typ +--- +"a" = Any +"f" = () -> Any +--- +27..28 -> @f +33..34 -> (@a | (Any) -> Any) +33..36 -> Any diff --git a/tests/e2e/main.rs b/tests/e2e/main.rs index 26e55a9b..6bb95b85 100644 --- a/tests/e2e/main.rs +++ b/tests/e2e/main.rs @@ -374,7 +374,7 @@ fn e2e() { }); let hash = replay_log(&tinymist_binary, &root.join("neovim")); - insta::assert_snapshot!(hash, @"siphash128_13:69e46cf64247dc4715e1bd46b33906df"); + insta::assert_snapshot!(hash, @"siphash128_13:cd78f76ced4e09f51c229ba2950bb8f2"); } {