Skip to content

Add resolution diagnostic for multi-output procedure in expression position#1116

Open
tautschnig wants to merge 3 commits intomainfrom
tautschnig/resolution-diagnostic
Open

Add resolution diagnostic for multi-output procedure in expression position#1116
tautschnig wants to merge 3 commits intomainfrom
tautschnig/resolution-diagnostic

Conversation

@tautschnig
Copy link
Copy Markdown
Contributor

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.

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

…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>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Comment thread Strata/Languages/Laurel/Resolution.lean Outdated
let name' ← defineNameCheckDup param.name (.var param.name ty')
pure (⟨.Declare ⟨name', ty'⟩, vs⟩ : VariableMd)
let savedFlag := (← get).inAssignRhs
modify fun s => { s with inAssignRhs := true }
Copy link
Copy Markdown
Contributor

@keyboardDrummer keyboardDrummer May 5, 2026

Choose a reason for hiding this comment

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

I think this won't work for issues that occur inside the RHS of an assignment. You need to set inAssignRhs to false when you find things that aren't assignments.

However, I think the easier to understand fix is to do type checking, which wouldn't rely on state. Could we ask a bot to add that to Resolution.lean? I don't think it's very difficult.

Something like:

Please add type checking to Resolution.lean. Let resolveStmtExpr return a ResolveM (StmtExprMd x HighTypeMd)and let the case for each StmtExpr constructor check that the types of its children are what is expected, if a particular type is expected.

Assigned this prompt to kbd-bot: #1120

Copy link
Copy Markdown
Contributor Author

@tautschnig tautschnig May 5, 2026

Choose a reason for hiding this comment

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

Done in 352fdf8352fdf8 (not the full type checking, though, which is left for #1120).

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Strata/Languages/Laurel/Resolution.lean Outdated
Comment thread Strata/Languages/Laurel/Resolution.lean Outdated
Comment thread Strata/Languages/Laurel/Resolution.lean Outdated
Address review feedback:
- Replace coarse inAssignRhs flag with inValueContext that is set when
  recursing into arguments of StaticCall/PrimitiveOp. This correctly
  diagnoses nested multi-output calls (e.g., f(multi(1))) while not
  firing for statement-position calls or direct assignment RHS.
- Factor out duplicate staticProcedure/instanceProcedure branches into
  a single outputCount lookup.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
Comment thread Strata/Languages/Laurel/Resolution.lean
These are all value contexts where a multi-output procedure call
would silently discard outputs.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
@keyboardDrummer
Copy link
Copy Markdown
Contributor

How about instead of this PR we look at merging #1121 ? I know this PR is a strict improvement, but I think it might be confusing to temporarily have this code. We'll have to make sure to remove it later as well. Since it's so easy to add a more long term solution, shouldn't we do that?

Copy link
Copy Markdown
Contributor

@keyboardDrummer keyboardDrummer left a comment

Choose a reason for hiding this comment

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

Prefer to wait for #1121, but approving in case you prefer not to wait

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.

3 participants