Skip to content

haskell args regex: signature-less equations measure 0, and qualified/dotted types truncate the :: signature capture #1511

Closed

Description

@squid-protocol

Summary

Found while verifying #1503-#1506 (the tree-sitter ground-truth fixes for args counting): after fixing the audit tool's ground truth, haskell's OWN args engine regex (in gitgalaxy/standards/language_standards.py, used by the real GitGalaxy scan, not just the accuracy-measurement tool) still had two real, distinct bugs causing args_exact_match to under-measure (31/81 -> 43/81 after the ground-truth fix alone).

Root cause 1: signature-less equations measure 0

Typeclass instance methods and where/let-local helpers routinely have no restated :: type signature at all (the same shape #1435/#1442 taught func_start to recognize). The args regex only knew how to count a :: signature's arrows, a lambda's params, or an @Type application -- none of which exist for e.g.:

isPandocCiteproc (JSONFilter f) = takeBaseName f == "pandoc-citeproc"

so args_count fell back to 0 regardless of true arity (real=1 per tree-sitter, got=0).

Root cause 2 (bigger impact): qualified/dotted type names truncate the :: capture

The :: signature's capture-group character classes never included .. Real-world Haskell overwhelmingly writes qualified/imported type names with a dot (T.Text, IO.Newline, M.Map) -- confirmed:

inquotes :: T.Text -> T.Text
inquotes txt = T.cons '\"' (T.snoc txt '\"')

captured only T (one letter) as the signature text -- zero arrows counted from a real 1-arrow signature, i.e. every arrow after the first dotted type silently vanished. This affected the majority of real corpus mismatches, since qualified imports are extremely common style (pandoc's corpus especially).

Fix (already implemented, see PR)

  • Added a new capture-group alternative to args for the signature-less equation's own LHS pattern list (name pat1 pat2 = ...), anchored to the absolute start of the block so it only ever reads the function's own first line. Routed through a new _count_haskell_pattern_list in detector.py (depth-and-string-aware, since a naive whitespace split wrongly splits a single parenthesized compound pattern like (MetaList xs) into two tokens). Explicitly excludes Haskell reserved keywords (let, where, data, etc.) from being mistaken for a function name -- confirmed let x = 1 (a value binding, not an equation) must never match.
  • Added . to the :: signature capture's character classes (both first-char and continuation) to stop the truncation at qualified type names.

args_exact_match: 31/81 (pre-#1503) -> 43/81 (ground-truth fix only) -> 70/81 (86.4%) with both engine fixes.

Remaining known gaps (NOT fixed, out of scope for this issue)

  • Arrow-count vs. actual-binding-arity divergence for point-free/partially-applied equations. A function like writerFn :: IO.Newline -> FilePath -> Text -> IO () with equations writerFn eol "-" = UTF8.putStrWith eol binds only 2 patterns per equation even though the signature has 3 arrows, because the body itself evaluates to a partially-applied function value (type Text -> IO ()). Tree-sitter's ground truth (equation pattern count) is arguably the more semantically correct measure here; GitGalaxy's arrow-counting can't distinguish "this arrow is a real curried parameter" from "this arrow is part of the point-free return type" without actual type inference. No regex fix available.
  • Haddock inline comments interrupting a multi-line signature capture, e.g.:
    tabFilter :: Int       -- ^ Tab stop
              -> T.Text    -- ^ Input
              -> T.Text
    The comment-skipping alternation only applies BEFORE the capture group opens, not between tokens inside it, so a trailing -- ^ ... haddock comment on an early line of a multi-line signature likely truncates it the same way the dot-bug did. Not chased in this issue -- would need the skippable-comment alternation folded into the capture group's own repetition, which needs its own careful ReDoS-safety pass.

This only affects extraction-pillar args-counting accuracy (epic #813) and the args_exact_match measurement (epic #1227/#1261), not risk scoring.

Activity

  1. added
    bug
    testing
    core-engine
    threat: false-negative
    on Aug 13, 2026
  2. added this to the v2.4.8 milestone on Aug 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcore-enginepriority: mediumtestingthreat: false-negative

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions