Skip to content

Fix multi-output calls in expression position (Python front-end)#1117

Draft
tautschnig wants to merge 2 commits intomainfrom
tautschnig/resolution-multi-output-diagnostic
Draft

Fix multi-output calls in expression position (Python front-end)#1117
tautschnig wants to merge 2 commits intomainfrom
tautschnig/resolution-multi-output-diagnostic

Conversation

@tautschnig
Copy link
Copy Markdown
Contributor

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

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

tautschnig and others added 2 commits May 5, 2026 16:25
…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>
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.

1 participant