Skip to content

Commit

Permalink
fix "there exists"/"such that" not followed by a var name (#538)
Browse files Browse the repository at this point in the history
  • Loading branch information
bakkot committed Jul 3, 2023
1 parent 9034ed3 commit 8c3a5ba
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lint/rules/variable-use-def.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ function walkAlgorithm(
if (
prev.name === 'text' &&
// prettier-ignore
/\b(?:for any |for some |there exists |there is |there does not exist )(\w+ )*$/.test(prev.contents)
/\b(?:for any |for some |there exists |there is |there does not exist )((?!of |in )(\w+ ))*$/.test(prev.contents)
) {
scope.declare(varName, part);
declaredThisLine.add(part);
Expand Down
16 changes: 16 additions & 0 deletions test/lint-variable-use-def.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,22 @@ describe('variables are declared and used appropriately', () => {
);
});

it('"there exists a value in _x_ with a property" does not declare _x_"', async () => {
await assertLint(
positioned`
<emu-alg>
1. If there exists an integer in ${M}_x_ greater than 0, return *true*.
1. Return *false*.
</emu-alg>
`,
{
ruleId: 'use-before-def',
nodeType: 'emu-alg',
message: 'could not find a preceding declaration for "x"',
}
);
});

it('variables in a loop header other than the loop variable must be declared', async () => {
await assertLint(
positioned`
Expand Down

0 comments on commit 8c3a5ba

Please sign in to comment.