Skip to content

fix(haskell): let func_start/args match guard-only defining equations - #1683

Merged
squid-protocol merged 5 commits into
mainfrom
fix/haskell-1616-guard-only-equations
Aug 15, 2026
Merged

squid-protocol merged 5 commits into
mainfrom
fix/haskell-1616-guard-only-equations

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Summary

Fixes #1616.

A local binding whose defining equation puts its guards (| cond = expr)
on separate, more-indented lines -- with no = anywhere on the naming/
pattern line itself -- was never matched. Distinct from #1615 (same-line
where, already fixed): here where/let is on its own line (or absent),
but the name+pattern line has no = at all:

isAllowedPunct c
  | extensionEnabled Ext_gfm_auto_identifiers exts = c == '-' || c == '_' || ...
  | otherwise = c == '_' || c == '-' || c == '.'

func_start's equation-anchored alternative required an = on the SAME
line as the captured name ((?=[ \t]+[^\s=][^\n=]*(?<![!<>/])=(?![=>])),
explicitly bounded to the current line), so a guard-only naming line was
invisible.

Fix

Captured the naming line's leading indent as a group and extended the
trailing lookahead to also accept a line with no =, immediately followed
on the NEXT line by a guard (|) at the exact same indent (backreference-
enforced against the captured indent group, not a general indent stack) --
mirrors the existing same-line = case without introducing unbounded
cross-line backtracking. Kept the sibling args rule's equivalent
alternative in sync, following the #1564/#1615 precedent.

Verification

$ venv/bin/pytest tests/extraction/languages/test_haskell.py tests/extraction/languages/test_haskell_strict.py -q
178 passed

$ tree_sitter_accuracy_audit.py --lang haskell
found_functions   139 -> 144  (+5: isAllowedPunct, stripBeginSpace now found)
extra_functions     2 ->   2  (unchanged, no new false positives)
args_exact_match  129 -> 133  (up)
tree_sitter_accuracy_audit: no regressions.

$ tree_sitter_accuracy_audit.py --all --ci
31 language(s) checked, all OK.

ReDoS: probed a 50k-char single line of | characters (no =), 50k lines
of invalid same/shallower-indent guards, and a stress case of 20,000 valid
guard-only functions via finditer over a synthetic doc -- all sub-second,
no catastrophic backtracking.

crucible_check.py --mode both blessed via --update --yes (expected
cascading drift). audit_check.py --ci clean.

Type of change

  • Bug fix
  • Parsing or engine logic (language_standards.py)

Differential Scan target

Haskell parser corpus (pandoc) -- the same files the issue's measurements came from.

Co-Authored-By: Claude Sonnet 5 [email protected]

squid-protocol and others added 3 commits August 15, 2026 16:23
A local binding whose defining equation puts its guards (| cond = expr) on
separate, more-indented lines -- with no '=' anywhere on the naming/pattern
line itself -- was never matched. Distinct from #1615 (same-line where):
here where/let is on its own line (or absent), but the name+pattern line
has no '=' at all, e.g.:

isAllowedPunct c
  | extensionEnabled Ext_gfm_auto_identifiers exts = c == '-' || ...
  | otherwise = c == '_' || c == '-' || c == '.'

func_start's equation-anchored alternative required an '=' on the SAME
line as the captured name. Captured the naming line's leading indent as a
group and extended the trailing lookahead to also accept a line with no
'=' immediately followed, on the next line, by a guard ('|') at the exact
same indent (backreference-enforced, not a general indent stack) --
mirrors the existing same-line '=' case without introducing unbounded
cross-line backtracking. Kept the sibling args rule's equivalent
alternative in sync, following the #1564/#1615 precedent.

found_functions 139 -> 144 (+5, isAllowedPunct and stripBeginSpace now
found), extra_functions unchanged at 2, args_exact_match 129 -> 133.

Fixes #1616

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@squid-protocol
squid-protocol enabled auto-merge (squash) August 15, 2026 20:30
squid-protocol and others added 2 commits August 15, 2026 16:51
…d-only-equations

# Conflicts:
#	gitgalaxy/standards/language_standards.py
#	tests/extraction/languages/test_haskell.py
#	tests/golden_master_audit.json
#	tests/golden_master_zero_dep_audit.json
#	tests/tree_sitter_accuracy_baseline_haskell.json
… slot

The #1616 guard-only fix newly exposed a pre-existing limitation in the
multi-clause dedup mechanism: a single (name, end) tracking slot broke as
soon as a differently-named match started nested inside the tracked span --
e.g. a `let`-bound guard-only local (`adjustNum`) inside an outer
multi-clause `go`'s own `do`-block, only visible after this issue's own
fix made it match at all. The inner match correctly needs its own tracking
slot (so its own siblings can dedup against it), but overwriting the single
slot lost the outer group's tracking entirely -- a later `go` clause, still
within the outer group's real span, then failed the name check and got
recorded as a spurious second "go" (confirmed on language-crucible's
pandoc/Shared.hs, extra_functions 2 -> 3).

Replaced the single-slot tracker with a stack of (name, end) frames.
Popping frames whose span has already closed (relative to the current
match's start) before each check lets a later match "return" to whichever
enclosing frame is still actually open, at any nesting depth, instead of
only ever comparing against the single most-recently-seen group.

found_functions 139 -> 144, extra_functions unchanged at 2 (the pre-existing
2, not the newly-introduced 3rd), args_exact_match 129 -> 133 -- the intended
#1616 improvement, now without the collateral regression.

Fixes #1616

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@squid-protocol
squid-protocol merged commit 9e57ad2 into main Aug 15, 2026
27 checks passed
@squid-protocol
squid-protocol deleted the fix/haskell-1616-guard-only-equations branch August 15, 2026 21:10
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

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.

haskell func_start: guard-only defining equations (no '=' on the naming line) are structurally invisible

1 participant