Skip to content

everywhere: Allow descructuring assignments#1620

Merged
alimpfard merged 3 commits into
SerenityOS:mainfrom
robryanx:tuple_new
Oct 7, 2025
Merged

everywhere: Allow descructuring assignments#1620
alimpfard merged 3 commits into
SerenityOS:mainfrom
robryanx:tuple_new

Conversation

@robryanx

@robryanx robryanx commented Oct 4, 2025

Copy link
Copy Markdown
Contributor

Currently we allow descructuring declarations for example:

let (x, y) = (1, 2)

This extends so that we can do destrucuting assignments for example:

mut x = 0
mut y = 0
(x, y) = (1, 2)

Additionally we can do nested destructuring for example:

mut x = 0
mut y = 0
mut z = 0
(x, (y, z)) = (1, (2, 3))

Will add this for declaration destructuring as part of a separate PR.

Note: This is similar to an older PR: #1161
The main difference being that it specifically only allows Var or JaktTuple for nesting on the LHS. Also the earlier PR had fairly significant parser changes but this version handles it within the typechecker without introducing parsing changes.

@BuggieBot

Copy link
Copy Markdown
Member

Hello!

One or more of the commit messages in this PR do not match the Jakt code submission policy, please check the lint_commits CI job for more details on which commits were flagged and why.
Please do not close this PR and open another, instead modify your commit message(s) with git commit --amend and force push those changes to update this PR.

@alimpfard

Copy link
Copy Markdown
Member

Very nice, I'll take a more comprehensive look in a bit but generally looks good.

@alimpfard alimpfard left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just one comment!

Comment thread selfhost/typechecker.jakt Outdated
Comment on lines +6736 to +6743
match expr {
BinaryOp(lhs, op, rhs) => {
if op is Assign and lhs is JaktTuple(values) {
return .typecheck_tuple_assignment(lhs_values: values, rhs, scope_id, safety_mode, span)
}
}
else => {}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

maybe better as an if?

Suggested change
match expr {
BinaryOp(lhs, op, rhs) => {
if op is Assign and lhs is JaktTuple(values) {
return .typecheck_tuple_assignment(lhs_values: values, rhs, scope_id, safety_mode, span)
}
}
else => {}
}
if expr is BinaryOp(lhs, op, rhs) and op is Assign and lhs is JaktTuple(values) {
return .typecheck_tuple_assignment(lhs_values: values, rhs, scope_id, safety_mode, span)
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, updated.

@robryanx
robryanx force-pushed the tuple_new branch 2 times, most recently from a5301b9 to 4ec8fb9 Compare October 7, 2025 10:05
@alimpfard

Copy link
Copy Markdown
Member

Thanks!

@alimpfard
alimpfard merged commit 424b388 into SerenityOS:main Oct 7, 2025
10 of 12 checks passed
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.

3 participants