Skip to content

Fix spurious error when assigning to a field on an as cast in a try block#5070

Open
SeanTAllen wants to merge 1 commit intomainfrom
fix-as-field-assign-in-try
Open

Fix spurious error when assigning to a field on an as cast in a try block#5070
SeanTAllen wants to merge 1 commit intomainfrom
fix-as-field-assign-in-try

Conversation

@SeanTAllen
Copy link
Copy Markdown
Member

Assigning to a field on the result of an as expression inside a try block produced a spurious error about consumed identifiers. The as operator desugars to a match with a consume of an internal hygienic variable, and the refer pass's ast_get_child function searched the entire assignment LHS subtree — including the desugared match's scope — for consumed variable names. This produced a false positive that triggered the verify pass error.

The fix stops ast_get_child from recursing into children that introduce their own scope. Variables bound in those scopes (like the match-internal hygienic variable) aren't assignment targets of the outer expression.

Closes #3604

… block

The `as` operator desugars to a match with a consume of an internal
hygienic variable. The refer pass's `ast_get_child` function searched
the entire assignment LHS subtree — including the desugared match's
scope — for consumed variable names, producing a false positive that
triggered the verify pass error. Stopping the search at scope
boundaries prevents descending into match-internal variables that
aren't assignment targets.

Closes #3604
@SeanTAllen SeanTAllen added the changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge label Mar 24, 2026
@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge discuss during sync Should be discussed during an upcoming sync

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compiler error on trying to assign a value to a cast object's property

2 participants