Skip to content

Move new variables declaration out of if , else, while and for blocks#619

Merged
thanhnguyen-aws merged 8 commits intostrata-org:mainfrom
thanhnguyen-aws:movevardecls
Mar 20, 2026
Merged

Move new variables declaration out of if , else, while and for blocks#619
thanhnguyen-aws merged 8 commits intostrata-org:mainfrom
thanhnguyen-aws:movevardecls

Conversation

@thanhnguyen-aws
Copy link
Copy Markdown
Contributor

@thanhnguyen-aws thanhnguyen-aws commented Mar 19, 2026

Description of changes: This PR remove new variables declaration inside if , else, while and for blocks and attach them before the those statements because Python allows using those variables outside of those blocks (they are not local).

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

joehendrix
joehendrix previously approved these changes Mar 20, 2026
Copy link
Copy Markdown
Contributor

@joehendrix joehendrix left a comment

Choose a reason for hiding this comment

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

Looks good — clean refactoring and the if/else hoisting correctly mirrors the try/except pattern. Two minor non-blocking notes inline.

shigoel
shigoel previously approved these changes Mar 20, 2026
@thanhnguyen-aws thanhnguyen-aws changed the title Move new variables declaration out of if and else blocks Move new variables declaration out of if , else, while and for blocks Mar 20, 2026
@thanhnguyen-aws thanhnguyen-aws added this pull request to the merge queue Mar 20, 2026
Merged via the queue into strata-org:main with commit ccf9f24 Mar 20, 2026
9 checks passed
@thanhnguyen-aws thanhnguyen-aws deleted the movevardecls branch March 20, 2026 21:36
github-merge-queue bot pushed a commit that referenced this pull request Mar 27, 2026
…639)

*Description of changes:* This PR move all variable declarations to the
beginning of the function body.

This PR continues the local variable bug fix from this PR
#619.
PR #619 moves the variable declarations inside the body blocks of `if`,
`while`, and `for` statements and attach them on the top of those
statements. However, in case those `if`, `while`, and `for` statements
are inside a sub-block, those variables are not accessible outside of
that block.
This PR resolves that issue by collecting all variables that appear
inside a function body and making declarations for them at the top of
the function body.

Note: To accommodate this task, this PR also adds overloaded types to
compositeTypeNames so that isCompositeType recognizes them during type
inference.

By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.

---------

Co-authored-by: Shilpi Goel <shigoel@gmail.com>
olivier-aws pushed a commit that referenced this pull request Mar 30, 2026
…639)

*Description of changes:* This PR move all variable declarations to the
beginning of the function body.

This PR continues the local variable bug fix from this PR
#619.
PR #619 moves the variable declarations inside the body blocks of `if`,
`while`, and `for` statements and attach them on the top of those
statements. However, in case those `if`, `while`, and `for` statements
are inside a sub-block, those variables are not accessible outside of
that block.
This PR resolves that issue by collecting all variables that appear
inside a function body and making declarations for them at the top of
the function body.

Note: To accommodate this task, this PR also adds overloaded types to
compositeTypeNames so that isCompositeType recognizes them during type
inference.

By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.

---------

Co-authored-by: Shilpi Goel <shigoel@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants