Skip to content

Support assignment in conditional parts of an expression#359

Open
keyboardDrummer wants to merge 14 commits intostrata-org:mainfrom
keyboardDrummer:conditionalAssignmentInExpression
Open

Support assignment in conditional parts of an expression#359
keyboardDrummer wants to merge 14 commits intostrata-org:mainfrom
keyboardDrummer:conditionalAssignmentInExpression

Conversation

@keyboardDrummer
Copy link
Contributor

Depends on #358

Changes

  • Support assignment in conditional parts of an expression

Testing

  • Added conditionalAssignmentInExpression test-case to test-file T2_ImpureExpressions

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

@keyboardDrummer keyboardDrummer requested a review from a team as a code owner January 30, 2026 14:38
Copy link
Contributor

@atomb atomb left a comment

Choose a reason for hiding this comment

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

This looks nice. My one comment could be addressed in a future PR, if at all.

@@ -45,7 +45,7 @@ def formatHighType : HighType → Format
Format.joinSep (types.map formatHighType) " & "

def formatStmtExpr (s:StmtExpr) : Format :=
Copy link
Contributor

Choose a reason for hiding this comment

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

Given the DDM-defined syntax for Laurel, is this function strictly needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes because the DDM grammar builds a parser/printer for a different type than the Laurel Lean type. There is only a transformation for the DDM type to the Lean type, but not vice versa, similar to Core.

@joscoh
Copy link
Contributor

joscoh commented Feb 4, 2026

This seems to have a lot of overlap with #358. What is the difference between them?

@keyboardDrummer
Copy link
Contributor Author

keyboardDrummer commented Feb 5, 2026

This seems to have a lot of overlap with #358. What is the difference between them?

This is stacked on top of that PR so it includes all the changes from that one, which sadly GH does not support well. Best to review this after that is merged.

From a user perspective, this PR enables this test:

procedure conditionalAssignmentInExpression(x: int) {
  var y: int := 0;
  var z: int := (if (x > 0) { y := y + 1; } else { 0 }) + y;
  if (x > 0) {
    assert y == 1;
    assert z == 2;
  } else {
    assert z == 0;
    assert y == 0;
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants