Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

round out tuple unpacking assignment, support underscores #22537

Merged
merged 3 commits into from
Aug 24, 2023

Conversation

metagn
Copy link
Collaborator

@metagn metagn commented Aug 23, 2023

fixes #18710

Tuple unpacking assignment ((a, b) = (1, 2)) now checks the type of the RHS properly for whether it's a tuple and whether it has the correct number of variables as opposed to delegating it to the tuple typeclass (#21767, supposedly this broke some macro code and a certain group blamed the separate VarTuple changes instead which if anything should make macros work better). The lowering code used to accomplish tuple unpacking assignment is now made into semantic code accordingly.

Underscores are also now supported, meaning (a, _) = (1, 2) is now possible when a is declared and _ isn't. This is a new feature so might have to be changelogged and documented, but it can be done later. The entire feature is 3 lines, 2 of which are else: and continue. This fixes #18710.

The temp that is generated by tuple unpacking assignment is also no longer named _ for clarity.

compiler/semexprs.nim Outdated Show resolved Hide resolved
Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
@Araq Araq merged commit 53d43e9 into nim-lang:devel Aug 24, 2023
15 of 16 checks passed
@github-actions
Copy link
Contributor

Thanks for your hard work on this PR!
The lines below are statistics of the Nim compiler built from 53d43e9

Hint: mm: orc; opt: speed; options: -d:release
169297 lines; 10.511s; 610.578MiB peakmem

metagn added a commit to metagn/Nim that referenced this pull request Dec 18, 2023
Araq pushed a commit that referenced this pull request Dec 18, 2023
closes #23042

Adds changes from #22537 and #22611 to changelog (I believe both are set
for 2.2).
narimiran pushed a commit that referenced this pull request Apr 17, 2024
* round out tuple unpacking assignment, support underscores

fixes #18710

* fix test messages

* use discard instead of continue

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>

---------

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
(cherry picked from commit 53d43e9)
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.

tuple destructuring doesn't always work with _ (underscore)
2 participants