mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-11-22 12:34:39 +00:00
fix: destructuring pattern handling in ExprWorker (#2244)
Some checks are pending
tinymist::auto_tag / auto-tag (push) Waiting to run
tinymist::ci / Duplicate Actions Detection (push) Waiting to run
tinymist::ci / Check Clippy, Formatting, Completion, Documentation, and Tests (Linux) (push) Waiting to run
tinymist::ci / Check Minimum Rust version and Tests (Windows) (push) Waiting to run
tinymist::ci / prepare-build (push) Waiting to run
tinymist::ci / announce (push) Blocked by required conditions
tinymist::ci / build (push) Blocked by required conditions
tinymist::gh_pages / build-gh-pages (push) Waiting to run
Some checks are pending
tinymist::auto_tag / auto-tag (push) Waiting to run
tinymist::ci / Duplicate Actions Detection (push) Waiting to run
tinymist::ci / Check Clippy, Formatting, Completion, Documentation, and Tests (Linux) (push) Waiting to run
tinymist::ci / Check Minimum Rust version and Tests (Windows) (push) Waiting to run
tinymist::ci / prepare-build (push) Waiting to run
tinymist::ci / announce (push) Blocked by required conditions
tinymist::ci / build (push) Blocked by required conditions
tinymist::gh_pages / build-gh-pages (push) Waiting to run
This PR corrects destructuring handling in `ExprWorker` by switching
`DestructuringItem::Named` to use `named.pattern()` rather than
`named.expr()`. According to ast definition (see `Named::pattern` in
0da0165954/crates/typst-syntax/src/ast.rs (L1418-L1433)
, the rhs of a `Named` pair must be interpreted as a pattern when it
appears inside a destructuring context, not as an expression. This
change ensures nested destructuring patterns are analyzed correctly.
Also, spread items (`..rest`) are normalized into pattern form and
registered as proper declarations.
So that now complex patterns like `#let (x: (used_a, unused_x), y: (c1,
c2, c3)) = (...)` and array spreads like `#let (first, ..rest) = (1, 2,
3)` are allowed to resolve and lint as intended.
This commit is contained in:
parent
15100abdde
commit
575b0e301e
1 changed files with 8 additions and 5 deletions
|
|
@ -516,7 +516,7 @@ impl ExprWorker<'_> {
|
|||
}
|
||||
ast::DestructuringItem::Named(named) => {
|
||||
let key = Decl::var(named.name()).into();
|
||||
let val = self.check_pattern_expr(named.expr());
|
||||
let val = self.check_pattern(named.pattern());
|
||||
names.push((key, val));
|
||||
}
|
||||
ast::DestructuringItem::Spread(spreading) => {
|
||||
|
|
@ -525,14 +525,17 @@ impl ExprWorker<'_> {
|
|||
} else {
|
||||
Decl::spread(spreading.span()).into()
|
||||
};
|
||||
let pattern = Pattern::Expr(Expr::Star).into();
|
||||
|
||||
if inputs.is_empty() {
|
||||
spread_left =
|
||||
Some((decl, self.check_pattern_expr(spreading.expr())));
|
||||
spread_left = Some((decl.clone(), pattern));
|
||||
} else {
|
||||
spread_right =
|
||||
Some((decl, self.check_pattern_expr(spreading.expr())));
|
||||
spread_right = Some((decl.clone(), pattern));
|
||||
}
|
||||
|
||||
self.resolve_as(Decl::as_def(&decl, None));
|
||||
self.scope_mut()
|
||||
.insert_mut(decl.name().clone(), decl.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue