Skip to content

Translate a for loop's initial value outside the loop variable's scope - #30

Merged
kondylidou merged 1 commit into
strata-org:mainfrom
calciiium:fix/for-loop-init
Nov 16, 2026
Merged

kondylidou merged 1 commit into
strata-org:mainfrom
calciiium:fix/for-loop-init

Conversation

@calciiium

Copy link
Copy Markdown
Contributor

toCoreStmt does not correctly translate a for loop's initial value: it reads it with the loop variable already bound, so variables resolve one binder off. For example, for i : int := lo to hi lowers to var i : int := hi, which lets main verify false contracts. All three for forms are affected.

The fix translates the initial value before binding the loop variable and adds for_loop_init.lean, which fails on main and passes with the fix.

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

toCoreStmt translated the initial value with the loop variable already
bound, so its variables resolved one binder off (`for i := lo to hi`
became `var i := hi`). Fix all three `for` forms; add for_loop_init.lean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@calciiium
calciiium marked this pull request as draft November 16, 2026 07:48
@calciiium
calciiium marked this pull request as ready for review November 16, 2026 07:50
@calciiium

Copy link
Copy Markdown
Contributor Author

@kondylidou Could you take a look when you get a chance?

@kondylidou
kondylidou self-requested a review November 16, 2026 08:38
@kondylidou

Copy link
Copy Markdown
Collaborator

Thanks, confirmed the bug and the fix locally. One optional suggestion: a negative case pinned as failing, e.g. the count_up loop with a false ensures, would guard the soundness direction directly. Fine as a follow-up.

@kondylidou
kondylidou merged commit 211d0c9 into strata-org:main Nov 16, 2026
2 checks passed
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.

2 participants