Skip to content

fix(base): normalize exhausted string prefixes - #1647

Open
oxura wants to merge 1 commit into
bendlang:mainfrom
oxura:fix/string-empty-prefix-20261017
Open

oxura wants to merge 1 commit into
bendlang:mainfrom
oxura:fix/string-empty-prefix-20261017

Conversation

@oxura

@oxura oxura commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Fixes #1640.

Once a prefix has been consumed, String.starts_with should not need to inspect the remaining haystack just to return True. The old haystack-first recursion left generic empty-prefix and known-prefix laws stuck.

This puts the internal recursion in pattern-first order while keeping the public (s, p) argument order. A separate internal go is needed because Bend does not allow matching an earlier binder after a later one. The old internal helper is removed, not aliased.

The new test checks empty prefixes, one- and two-character prefixes over arbitrary tails, and an early mismatch over arbitrary tails. The same empty-prefix program fails --check-only on e5527d5 and passes after this change. This is a normalization improvement, not a soundness fix. AI-assisted.

Checked with the independent Lean 4.34 kernel: both the new generic prefix laws and the existing string_contains laws report ALL PROOFS CHECK. The new program also runs on C and JS; the existing string-kit program keeps all 36 expected outputs on both targets.

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.

Let an empty String prefix reduce without inspecting the haystack

1 participant