Fix multi-output calls in expression position (Python front-end)#1117
Draft
tautschnig wants to merge 2 commits intomainfrom
Draft
Fix multi-output calls in expression position (Python front-end)#1117tautschnig wants to merge 2 commits intomainfrom
tautschnig wants to merge 2 commits intomainfrom
Conversation
…sition When a StaticCall to a multi-output procedure appears in expression position (not as the RHS of an Assign), emit an error diagnostic: the extra outputs would be silently discarded, which is a semantic bug (e.g., error channels lost). The diagnostic is suppressed when the call is the direct RHS of an assignment (where the target count check already validates arity). Includes a test in ResolutionKindTests demonstrating the diagnostic. Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
When translateExpr produces an expression containing a nested multi- output procedure call (e.g., PSub(base, timedelta_func(...))), the new extractMultiOutputCalls pass in translateAssign rewrites it into a preceding multi-target assignment and a variable reference: var $mo_0 := ...; assign $mo_0, maybe_except := timedelta_func(...); delta := PSub(base, $mo_0) This prevents multi-output calls from appearing in expression position, which would silently discard the error channel. Changes: - Add extractMultiOutputCalls (StateM Nat) and translateExprExtractingCalls in PythonToLaurel.lean - Extend containsUserCall to detect multi-output prelude calls and Blocks (preventing duplication in exception checks) - Add containsBareAssignment in LiftImperativeExpressions.lean that skips Blocks, used by assert/assume handlers - Add Block-flattening in the lifter for generated multi-output wrappers (pattern: [VarDecl, MultiAssign(2+ targets), VarRef]) - Restore test_procedure_in_assert.py with the original multi-output call in expression position (base - timedelta(days=7)) Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
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.
When translateExpr produces an expression containing a nested multi-output procedure call (e.g., PSub(base, timedelta_func(...))), the new extractMultiOutputCalls pass in translateAssign rewrites it into a preceding multi-target assignment and a variable reference:
var $mo_0 := ...; assign $mo_0, maybe_except := timedelta_func(...);
delta := PSub(base, $mo_0)
This prevents multi-output calls from appearing in expression position, which would silently discard the error channel.
Changes:
Co-authored-by: Kiro kiro-agent@users.noreply.github.com
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.