Skip to content

typescript func_start: interface/type function-typed member declarations misidentified as real function definitions (majority of 309 extra_functions) #1631

Closed

Description

@squid-protocol

Summary

tests/tools/tree_sitter_accuracy_audit.py --lang typescript measures 309 extra_functions (false positives) against language-crucible/data/typescript, dragging func_precision to 85.6%. Full diff (not just the tool's 8-file sample) shows the dominant driver: func_start's colon-annotated-arrow branch cannot distinguish a real arrow-function value assignment from an interface/type member declared with a function-type annotation — both share the identical IDENT: (params) => ReturnType surface syntax, but only one has an actual implementation. GitGalaxy reports a phantom function for every function-typed interface/type field.

Root cause

gitgalaxy/standards/language_standards.py's typescript func_start rule's third alternative:

r"^[ \t]*[a-zA-Z_$][\w$]*(?=[ \t\n]*:[ \t\n]*(?:async\s*)?(?:<(?:[^<>]|<[^<>]*>)*>\s*)?(?:function(?:\s*\*)?\b|\([^)]*\)[^=;{]*=>|[a-zA-Z_$][\w$]*[ \t\n]*=>))|"

matches any IDENT: followed eventually by (...) => ..., with no requirement that an actual = assignment or { body ever follows. That's correct for an object-literal method-shorthand-style property ({ foo: (x) => x + 1 }, a real function), but the exact same shape also describes an interface/type member's function-type annotation, which is pure type-level syntax with no runtime function at all:

export interface PipeableApply2<F extends URIS2> extends PipeableFunctor2<F> {
  readonly chainFirst: <S, R, E, A, B>(
    f: (a: A) => Kind4<F, S, R, E, B>
  ) => (ma: Kind4<F, S, R, E, A>) => Kind4<F, S, R, E, A>
}

Here f: (a: A) => Kind4<F, S, R, E, B> is a parameter's type annotation, one level nested inside chainFirst's own function-type signature — not a definition. GitGalaxy reports a phantom function named f.

Confirmed directly against the regex:

>>> rule.finditer('''export interface Foo {
...   readonly chainFirst: <S, R, E, A, B>(
...     f: (a: A) => Kind4<F, S, R, E, B>
...   ) => (ma: Kind4<F, S, R, E, A>) => Kind4<F, S, R, E, A>
... }''')
[<Match 'f' at pos 63>]   # false positive -- `f` is a parameter's type annotation, not a function

This is the same ambiguity class already solved for the sibling type X = (...) => ... alias case (a fixed-width negative lookbehind for type , per this same rule's own comments) — but that fix only covers the top-level type Foo = ... alias shape, not an arbitrary-depth nested member inside an interface/type body.

Evidence (scale)

extra_functions names are overwhelmingly the single/short parameter names used inside these generic function-type signatures — f, g, B, etc. — repeated dozens of times per file. Confirmed counts from the full diff:

  • 29 of 309 extra matches have a name of 2 characters or fewer (f, g, B, ...)
  • language-crucible/data/typescript/fp-ts/pipeable.ts alone contributes ~20+ f/g false positives (heavily-generic Pipeable* interfaces, lines 1326-2103), e.g.:
    fp-ts/pipeable.ts:1326  f  (from `readonly chainFirst: <S,R,E,A,B>(\n  f: (a: A) => Kind4<...>\n) => ...`)
    fp-ts/pipeable.ts:1900  f  (same shape, partitionMapWithIndex)
    
  • Also present with longer names once a real property is misread the same way (onmessage in playwright/connection.ts and playwright/dispatcher.ts, addAntecedent/forEach in typescript_compiler/binder.ts).

Suggested fix direction

The general shape to detect and exclude: the match sits inside an enclosing interface { ... } / type X = { ... } body's member-type position (as opposed to an object literal, { ... } following =). Without full scope tracking this is hard to do with a pure lookaround, but a narrower, still-high-value fix: this branch's match only ever needs to fire for a parameter of an outer arrow/function type when nested — i.e. when the immediately preceding non-whitespace character (skipping the current line's own indentation) is ( or , from an already-open parameter list opened by a still-in-progress func_start-shaped signature. That's exactly the situation in every cited example (f/g always appear as the first thing after ( or ,\n inside another signature's own parens). Worth scoping precisely against the corpus before committing to an approach — flagging the shape and evidence here rather than prescribing the fix.

Filed under epic #1261, alongside #1629/#1630 (same corpus/diagnosis pass, false-positive counterpart to those two false-negative issues).

Activity

  1. added
    bug
    testing
    core-engine
    threat: false-positive
    on Aug 14, 2026
  2. squid-protocol commented on Aug 15, 2026

    @squid-protocol
    OwnerAuthor

    @uuzzrm interested in following up on this one?

  3. uuzzrm commented on Aug 15, 2026

    @uuzzrm
    Contributor

    Happy to take this one — it’s the same ambiguity class I just fixed in #1630, one level deeper. I’ll scope it against the corpus first (the fp-ts pipeable.ts cases are a good stress test) and come back with the precision numbers before opening a PR.

  4. uuzzrm commented on Aug 15, 2026

    @uuzzrm
    Contributor

    Opened #1654 for this. Root cause confirmed exactly as scoped: the colon-annotated-arrow branch matches parameter annotations inside interface member signatures. The fix drops line-anchored matches whose preceding non-whitespace char is ( - the position a nested parameter always occupies - and the corpus numbers back it up: extra_functions 299 to 275 with zero recall loss (found_functions flat at 1876). The remaining extras are the interface-member shape you flagged as needing scope-tracking, which is a separate follow-up.

  5. 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-positive

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions