Skip to content

Filter keywords from zlup identifier proptests and fix the unreachable orelse keyword alternative - #537

Merged
ciaranra merged 2 commits into
devfrom
fix-zlup-keyword-proptest
Aug 17, 2026
Merged

Filter keywords from zlup identifier proptests and fix the unreachable orelse keyword alternative#537
ciaranra merged 2 commits into
devfrom
fix-zlup-keyword-proptest

Conversation

@ciaranra

Copy link
Copy Markdown
Member

Closes #419.

The reported bug

valid_identifiers_accepted generated raw [a-zA-Z_][a-zA-Z0-9_]* strings, so proptest eventually produces a keyword (minimal input fn), which the parser correctly refuses — the property asserted something false. parser_valid_function had the same latent defect in its function-name strategy (a generated name like if or true makes the source unparseable); the three remaining identifier-generating properties are guarded by if let Ok and merely skip keyword inputs, so they are left as-is.

Fix

The grammar is now the single source of truth for what counts as a keyword: zlup::parser::is_keyword matches a candidate against the grammar's own keyword rule (exact-length match), and both asserting properties prop_assume! keywords away through it. No keyword list is duplicated into the tests.

A real grammar bug this surfaced

Pinning is_keyword deterministically exposed that the keyword rule could never match orelse: pest's ordered choice matched the "or" alternative first, the trailing !(ASCII_ALPHANUMERIC | "_") lookahead then failed on e, and PEG parsing does not backtrack into a matched alternative. Because identifier is defined as !keyword ~ ..., the parser accepted orelse := 42; as an ordinary identifier assignment. The rule now lists "orelse" before "or". An audit of the full keyword list found no other prefix-shadowed pair (errdefer/error, union/unit, and try/true all diverge before either token ends). No example or test program used orelse as an identifier, and all five orelse-operator tests still pass.

keywords_are_rejected_as_identifiers pins the behavior in both directions: representative keywords (including orelse) are recognized and refused as identifiers, while near-keywords such as fnord, iffy, and returned remain valid.

Verification

Full cargo test -p zlup (666 unit + 175 proptest + CLI suites) green; cargo fmt --check, cold cargo clippy --locked -p zlup --all-targets -- -D warnings, and pre-commit run --all-files clean. The new pin test demonstrably fails against the unfixed grammar (that is how the orelse defect was found) and passes after the reorder.

@ciaranra
ciaranra merged commit 8fc5502 into dev Aug 17, 2026
20 checks passed
@ciaranra
ciaranra deleted the fix-zlup-keyword-proptest branch August 17, 2026 01:03
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.

zlup identifier proptest generates keywords and fails on "fn"

1 participant