fix(transpiler): @when result assignment silently dropped in exported module#30
Open
xemishra wants to merge 1 commit into
Open
fix(transpiler): @when result assignment silently dropped in exported module#30xemishra wants to merge 1 commit into
xemishra wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
WhenTransformer.visit_FunctionDefintranspiler.pywas returningast.Expr(ast.Assign(...))anast.Assignstatement incorrectlywrapped inside an
ast.Exprnode.This caused a silent double failure:
ast.Assignis a statement, not an expression, so the wrappingviolates the Python AST contract.
visit_Modulefilters out everyast.Exprnode to strip bareexpression statements. Because the return value matched that filter,
the
name = whencall(...)assignment was thrown away entirely.Impact
For every
@when-decorated function, the variable that should holdthe result
Cownwas never assigned in the exported module. Any codethat read
.value, checked.exception, or chained behaviors on theresult was operating on
None(or whatever the name happened to bebound to previously), with no error at schedule time.
Root cause
Fix
Returning a bare
ast.Assignpasses thevisit_Modulefiltercorrectly, satisfies the AST node contract, and ensures the result
Cownis bound to the user's chosen name in the exported module.Testing
Verified by invoking
export_module()directly on a minimal sourcecontaining a
@when-decorated function and asserting thatname = whencall(...)appears in the unparsed output, which it didnot before this fix.