Skip to content

✨ feat(mq-lang): add destructuring assignment for let/var#1466

Merged
harehare merged 10 commits intomainfrom
feat/destructuring-assignment
Mar 18, 2026
Merged

✨ feat(mq-lang): add destructuring assignment for let/var#1466
harehare merged 10 commits intomainfrom
feat/destructuring-assignment

Conversation

@harehare
Copy link
Copy Markdown
Owner

Support array and dict patterns on the left-hand side of let/var declarations.

Support array and dict patterns on the left-hand side of let/var declarations.
Copilot AI review requested due to automatic review settings March 18, 2026 03:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds destructuring patterns to let/var declarations in mq-lang, with corresponding runtime evaluation, parsing updates (AST + CST), HIR lowering changes, and documentation/tests to validate the new syntax.

Changes:

  • Extend AST/CST parsers so let/var LHS can be an array/dict pattern (e.g. let [a, b] = ..., let {x} = ...).
  • Evaluate let/var by matching the RHS value against a pattern and binding all extracted names (or erroring on mismatch).
  • Update HIR lowering + docs + integration/property tests for the new pattern forms.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
docs/books/src/reference/variables.md Documents destructuring declarations for let/var, including array/dict/rest examples.
crates/mq-run/tests/integration_tests.rs Adds CLI-level integration tests for destructuring success cases.
crates/mq-lang/tests/property_based_tests.rs Updates generators to build Let/Var with AstPattern::Ident(...).
crates/mq-lang/src/module.rs Updates module parsing tests to construct Let with Pattern::Ident(...).
crates/mq-lang/src/macro_expand.rs Propagates patterns through macro expansion/substitution for Let/Var.
crates/mq-lang/src/lib.rs Re-exports AstPattern.
crates/mq-lang/src/eval.rs Implements destructuring binding via match_pattern for Let/Var (and module var loading).
crates/mq-lang/src/error/runtime.rs Adds RuntimeError::DestructuringFailed.
crates/mq-lang/src/error.rs Adds diagnostic/help text for destructuring failures.
crates/mq-lang/src/cst/parser.rs Parses let/var LHS as pattern nodes when starting with [/{.
crates/mq-lang/src/ast/parser.rs Parses let/var LHS into Pattern (array/dict/ident).
crates/mq-lang/src/ast/node.rs Changes Expr::Let/Var to store a Pattern instead of an identifier.
crates/mq-lang/src/ast/code.rs Formats let/var patterns back to source; adds unit tests for pattern formatting.
crates/mq-hir/src/hir/lower.rs Lowers let/var destructuring LHS via add_pattern_expr.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 18, 2026

Merging this PR will not alter performance

✅ 29 untouched benchmarks


Comparing feat/destructuring-assignment (3cc01b9) with main (a5a8514)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (8acb567) during the generation of this report, so a5a8514 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

Copilot AI review requested due to automatic review settings March 18, 2026 06:16
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds destructuring patterns to let/var declarations in mq-lang, with corresponding updates to parsing/AST, runtime evaluation, LSP UX, docs, and integration tests.

Changes:

  • Extend AST/CST parsers and AST node model so let/var accept array/dict patterns (plus array rest ..).
  • Update evaluator/module loading to bind variables produced by pattern matching, and introduce a runtime error for pattern mismatch.
  • Surface pattern-bound variables in LSP hover/completions and document/test the new syntax.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
docs/books/src/reference/variables.md Documents destructuring usage for let/var (array/dict/rest)
crates/mq-run/tests/integration_tests.rs Adds CLI-level integration tests for destructuring declarations
crates/mq-lsp/src/hover.rs Includes PatternVariable symbols in hover output
crates/mq-lsp/src/completions.rs Includes PatternVariable symbols in completion items
crates/mq-lang/tests/property_based_tests.rs Updates generators to use AstPattern::Ident for let/var
crates/mq-lang/src/module.rs Updates module parsing test expectations for pattern-based let
crates/mq-lang/src/macro_expand.rs Propagates pattern-based let/var through macro expansion/substitution
crates/mq-lang/src/lib.rs Re-exports AstPattern from the AST module
crates/mq-lang/src/eval.rs Implements pattern binding for let/var and module var initialization
crates/mq-lang/src/error/runtime.rs Adds RuntimeError::DestructuringFailed
crates/mq-lang/src/error.rs Adds diagnostic help text for destructuring mismatch
crates/mq-lang/src/cst/parser.rs Allows LHS pattern nodes in CST let/var declarations
crates/mq-lang/src/ast/parser.rs Parses let/var LHS as a Pattern (ident/array/dict)
crates/mq-lang/src/ast/node.rs Changes Expr::{Let,Var} to store Pattern instead of IdentWithToken
crates/mq-lang/src/ast/code.rs Updates AST-to-code formatting to print patterns for let/var
crates/mq-hir/src/hir/lower.rs Lowers destructuring let/var into pattern-related HIR symbols

Copilot AI review requested due to automatic review settings March 18, 2026 10:45
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds destructuring patterns to let/var declarations in mq-lang, and wires the feature through parsing → evaluation → HIR → type checking → LSP, with docs and CLI integration tests to validate behavior end-to-end.

Changes:

  • Extend CST/AST parsing and AST printing to allow array/dict patterns on let/var LHS.
  • Implement runtime destructuring via pattern matching in the evaluator, with a dedicated runtime error on mismatch.
  • Add HIR + type-checker + LSP support for destructuring bindings, plus new integration tests and reference docs.

Reviewed changes

Copilot reviewed 26 out of 26 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
docs/books/src/reference/variables.md Documents destructuring let/var syntax with examples.
crates/mq-run/tests/integration_tests.rs Adds CLI integration tests for array/dict destructuring and mutation via var.
crates/mq-lsp/src/semantic_tokens.rs Classifies destructuring bindings for semantic token output.
crates/mq-lsp/src/inlay_hints.rs Includes destructuring bindings in type inlay hints.
crates/mq-lsp/src/hover.rs Adds hover support for destructuring-related symbol kinds.
crates/mq-lsp/src/document_symbol.rs Treats destructuring bindings similarly to variables for document symbols.
crates/mq-lsp/src/completions.rs Exposes destructuring-related symbol kinds in completions.
crates/mq-lang/tests/property_based_tests.rs Updates AST generators to build Let/Var using AstPattern.
crates/mq-lang/src/module.rs Updates module test AST to use Pattern::Ident for Let.
crates/mq-lang/src/macro_expand.rs Updates macro expansion/substitution to clone Let/Var patterns.
crates/mq-lang/src/lib.rs Re-exports AstPattern.
crates/mq-lang/src/eval.rs Implements destructuring semantics for let/var via match_pattern.
crates/mq-lang/src/error/runtime.rs Adds RuntimeError::DestructuringFailed.
crates/mq-lang/src/error.rs Adds a diagnostic help message for destructuring failures.
crates/mq-lang/src/cst/parser.rs Parses let/var LHS as either ident or pattern ([]/{}).
crates/mq-lang/src/ast/parser.rs Parses let/var patterns into Pattern (array/dict/ident).
crates/mq-lang/src/ast/node.rs Changes Expr::Let/Var to store Pattern instead of IdentWithToken.
crates/mq-lang/src/ast/code.rs Prints let/var with patterns via format_pattern + adds formatting tests.
crates/mq-hir/src/symbol.rs Introduces SymbolKind::DestructuringBinding and treats it as variable-like.
crates/mq-hir/src/resolve.rs Includes DestructuringBinding in resolution priority rules.
crates/mq-hir/src/hir/lower.rs Lowers destructuring let/var into DestructuringBinding + pattern variable symbols.
crates/mq-hir/src/hir.rs Adds a HIR test asserting destructuring lowering structure.
crates/mq-check/src/constraint/pipe.rs Propagates piped input through destructuring binding initializers like variables.
crates/mq-check/src/constraint/helpers.rs Adds helper to collect PatternVariable descendants for destructuring constraints.
crates/mq-check/src/constraint/categories.rs Categorizes DestructuringBinding for constraint passes.
crates/mq-check/src/constraint.rs Adds constraint generation logic for destructuring bindings (array/dict).
Comments suppressed due to low confidence (1)

crates/mq-lsp/src/semantic_tokens.rs:94

  • SymbolKind::DestructuringBinding is emitted as a semantic token using its full text_range (currently the entire pattern range like [a, b]). This will overlap with the Pattern/PatternVariable tokens inside the pattern, which violates LSP semantic token requirements (tokens must be non-overlapping) and can break highlighting in clients. Suggestion: don’t produce semantic tokens for DestructuringBinding (or ensure its range does not overlap, e.g. by not assigning it a text_range in HIR).
                mq_hir::SymbolKind::Variable
                | mq_hir::SymbolKind::DestructuringBinding
                | mq_hir::SymbolKind::Symbol
                | mq_hir::SymbolKind::MatchArm
                | mq_hir::SymbolKind::Pattern
                | mq_hir::SymbolKind::PatternVariable
                | mq_hir::SymbolKind::Ident => token_type(ls_types::SemanticTokenType::VARIABLE),

Copilot AI review requested due to automatic review settings March 18, 2026 12:54
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds destructuring patterns to mq’s let/var declarations, wiring the feature through parsing, runtime evaluation, HIR/lowering, type inference, and editor tooling.

Changes:

  • Extend CST/AST parsing so let/var accept array/dict patterns on the LHS.
  • Implement runtime binding of destructured values (and a new runtime error on mismatch).
  • Teach HIR, type constraints, and LSP/wasm tooling to recognize destructuring-related symbols; add integration/type-check tests and docs.

Reviewed changes

Copilot reviewed 28 out of 28 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
docs/books/src/reference/variables.md Documents destructuring for let/var with examples.
crates/mq-wasm/src/script.rs Shows inlay hints for destructuring bindings/pattern variables in wasm tooling.
crates/mq-run/tests/integration_tests.rs Adds CLI integration tests for destructuring success cases + regression.
crates/mq-lsp/src/semantic_tokens.rs Classifies destructuring-related symbols for semantic highlighting.
crates/mq-lsp/src/inlay_hints.rs Includes destructuring bindings in LSP inlay-hints eligibility.
crates/mq-lsp/src/hover.rs Adds hover support for destructuring bindings/pattern variables.
crates/mq-lsp/src/document_symbol.rs Includes destructuring binding symbols in document-symbol output.
crates/mq-lsp/src/completions.rs Includes destructuring binding/pattern variables in completion candidates.
crates/mq-lang/tests/property_based_tests.rs Updates generators to match new Let/Var(Pattern, ...) AST shape.
crates/mq-lang/src/module.rs Updates module tests/fixtures for new let AST representation.
crates/mq-lang/src/macro_expand.rs Updates macro expansion/substitution to preserve let/var patterns.
crates/mq-lang/src/lib.rs Re-exports AstPattern.
crates/mq-lang/src/eval.rs Implements destructuring binding evaluation for let/var.
crates/mq-lang/src/error/runtime.rs Adds RuntimeError::DestructuringFailed.
crates/mq-lang/src/error.rs Adds diagnostic/help text for destructuring failure runtime error.
crates/mq-lang/src/cst/parser.rs Parses pattern forms ([...] / {...}) on let/var LHS in CST.
crates/mq-lang/src/ast/parser.rs Parses let/var LHS into Pattern (array/dict/ident).
crates/mq-lang/src/ast/node.rs Changes Expr::Let/Var to store Pattern instead of IdentWithToken; defines Pattern.
crates/mq-lang/src/ast/code.rs Formats let/var patterns back to code; adds format tests for patterns.
crates/mq-hir/src/symbol.rs Adds DestructuringBinding; refines Pattern/PatternVariable kinds.
crates/mq-hir/src/resolve.rs Updates symbol priority rules for new symbol kinds.
crates/mq-hir/src/hir/lower.rs Lowers destructuring let/var into DestructuringBinding + pattern children; tracks rest bindings and dict keys.
crates/mq-hir/src/hir.rs Updates HIR tests and adds destructuring-binding HIR test coverage.
crates/mq-check/tests/type_errors_test.rs Adds type-check tests for dict destructuring (shorthand + explicit key).
crates/mq-check/src/constraint/pipe.rs Propagates piped input to destructuring initializer like normal variables.
crates/mq-check/src/constraint/helpers.rs Adds helper to collect PatternVariable descendants for constraints.
crates/mq-check/src/constraint/categories.rs Categorizes destructuring binding / pattern variable symbols for constraint passes.
crates/mq-check/src/constraint.rs Adds constraint generation for destructuring bindings (array + dict).

@harehare harehare merged commit ec24cb6 into main Mar 18, 2026
10 checks passed
@harehare harehare deleted the feat/destructuring-assignment branch March 18, 2026 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants