An assignment used as an expression, such as `(x = 7);` or `const y = (x = 7)`, is extracted as an equality test, so a false `ensures` can verify
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 3/5
- Estimated time
- Half a day
- Newbie friendliness
- 30/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript
- Domain
- compilers
Research direction
Start in tools/src/extract.ts: the op === "=" branch in extractExpr (around line 516) emits a binop that later becomes ==, and desugarStmtExpr (around line 1350) does not unwrap a ParenthesizedExpression before checking for an assignment. Done means (x = 7); and const y = (x = 7); lower to an assignment or a source-positioned error, and the parenWholeAssign example no longer verifies. Note that pull request #363 is already open against this issue.
Written by the indexing model from the issue text.
Description
Problem
When a JavaScript assignment appears in expression position, extract turns it into the IR's equality operator. (x = 7); and const y = (x = 7); therefore emit x == 7, the assignment disappears, and a false ensures verifies.
Reproduced on upstream main at 2ccd0a5 (0.6.11) with Dafny 4.11.0.
Reproduction
export function parenWholeAssign(p: number): number {
//@ ensures p === 0 ==> \result === 0
let x = p;
(x = 7);
return x;
}
parenWholeAssign(0) returns 7 in JavaScript. lsc gen --backend=dafny emits:
method parenWholeAssign(p: int) returns (res: int)
ensures ((p == 0) ==> (res == 0))
{
var x := p;
var _ := (x == 7);
return x;
}
and dafny verify reports 1 verified, 0 errors.
The same happens with an assignment in an initializer:
export function assignInInit(p: number): number {
//@ ensures p === 0 ==> \result === 0
let x = p;
const y = (x = 7);
return x;
}
emits var y := (x == 7); and verifies (1 verified, 0 errors), while JavaScript returns 7.
if ((x = 7) > 0) emits if ((x == 7) > 0), which Dafny rejects as a type error, so that form fails loudly.
Expected
A parenthesized assignment statement such as (x = 7); should be lowered the same way as x = 7;. An assignment anywhere else inside an expression should either be supported or be rejected with a source-positioned error. It should never become an equality test.
Likely cause
In tools/src/extract.ts:
extractExprhandlesop === "="by returning{ kind: "binop", op: "=", ... }(around line 516, commented "extract as binop for now"). Later passes treat binop"="as equality, which the Dafny emitter prints as==.desugarStmtExpr(line 1350) checksNode.isBinaryExpression(expr)without unwrapping aParenthesizedExpression, so(x = 7);falls through to an expression statement and reaches the branch above. Theforincrementor path also callsdesugarStmtExpr.
Related
- #355: a parenthesized assignment target,
(x) = 7, in the same function. That one fails to parse in Dafny. Both need parentheses unwrapped indesugarStmtExpr.
- Dominant language
- TypeScript
- Stars
- 113
- Forks
- 13
- Avg merge
- 15h 35m
- Merged PRs (30d)
- 56
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from midspiral/LemmaScript
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
midspiral/LemmaScript#355 · 1 comment ·
Maintainers usually reply within 1 day
-
In a pure function body, a `const` declared inside an `if` branch stays in scope after the `if`, so a false `ensures` can verifyPossibly taken @namin claimed this today. Open
Difficulty 4/5 3-5 days Newbie friendliness 25/100
midspiral/LemmaScript#362 ·
Maintainers usually reply within 1 day
-
A `const` or `let` inside a bare `{ }` block stays in scope after the block, so a false `ensures` can verifyPossibly taken @namin claimed this today. Open
Difficulty 4/5 3-5 days Newbie friendliness 15/100
midspiral/LemmaScript#361 ·
Maintainers usually reply within 1 day
-
A closure declared before a same-name `const` or `let` in its block reads the outer variable, so a false `ensures` can verifyPossibly taken @namin claimed this today. Open
Difficulty 4/5 3-5 days Newbie friendliness 18/100
midspiral/LemmaScript#360 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 62/100
midspiral/LemmaScript#354 ·
Maintainers usually reply within 1 day
All issues in midspiral/LemmaScript
Similar issues
-
bug done
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
neavo/LinguaGacha#1124 ·
Maintainers usually reply within 1 day
-
[fullsend] E2E: backstage-microsoft-auth — catalogQuery missing error handler for network errorsPossibly taken @fullsend-ai-coder claimed this today. Opene2e-failure ready-to-code
Difficulty 2/5 Under an hour Newbie friendliness 78/100
redhat-developer/rhdh-plugin-export-overlays#4821 · 1 comment ·
Maintainers usually reply within 1 day
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
brylie/mission-island#225 ·
Maintainers usually reply within 1 day
-
status/need-triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
google-gemini/gemini-cli#30412 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day