Skip to content

Support tuple targets in for loops#469

Open
Green00101 wants to merge 1 commit into
spylang:mainfrom
Green00101:fix/for-loop-unpack-target
Open

Support tuple targets in for loops#469
Green00101 wants to merge 1 commit into
spylang:mainfrom
Green00101:fix/for-loop-unpack-target

Conversation

@Green00101

Copy link
Copy Markdown

Closes #455

Summary

This PR adds support for tuple targets in for loops.

Example:

for a, b in pairs:
    pass

Before this change, for loops only supported a single name target.

Changes

  • allow ast.For.target to be either a single name or a list of names
  • parse tuple targets in for loops
  • declare and flatten all names from tuple targets
  • emit UnpackAssign in _desugar_For for tuple targets
  • update backend output to print for a, b in pairs:

Notes

This PR supports simple tuple targets only.
Nested unpacking is still rejected.

Testing

Added tests for parser and backend output.

While testing, I found a separate doppler issue:
for t in lst fails when lst is list[tuple[...]], with what seems to be a gc_ref[tuple] vs tuple mismatch.

Because that looks independent from tuple targets in for loops, I did not include that compiler-level test in this PR.

Happy to make any changes if needed.

@antocuni

Copy link
Copy Markdown
Member

Hello @Green00101.
Before I review, could you please disclose whether you used any AI assistant and, in case, how much?

@Green00101

Copy link
Copy Markdown
Author

Sure.

I first used Opus to understand the codebase and identify the key functions I should focus on. Then, I used ChatGPT to help me understand how those important functions work.

Next, I tried to add code to the codebase by myself. After that, I used ChatGPT to review my code and make changes based on its feedback.

Finally, I used Opus to generate test cases. During this process, I encountered a strange failure that I could not understand. I asked three different AI tools about it, and they all gave me the same answer: it was a Doppler issue. So I mentioned that in the description.

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 unpacking in for loops

2 participants