Skip to content

[TypeScript] func_start's reserved-keyword shield excludes legitimate catch method name #2276

Closed

Description

@squid-protocol

During a tri-comparison ledger sweep (typescript backlog, docs/self_scan/tri_comparison_ledger.json), a full-corpus func_start diff against tree-sitter found that GitGalaxy's TypeScript func_start regex never matches a real method/function named catch.

Real example, vscode/async.ts:74 (a Promise-like thenable class):

then<TResult1 = T, TResult2 = never>(resolve?: ..., reject?: ...): Promise<TResult1 | TResult2> {
    return promise.then(resolve, reject);
}
catch<TResult = never>(reject?: ((reason: unknown) => TResult | Promise<TResult>) | undefined | null): Promise<T | TResult> {
    return this.then(undefined, reject);
}
finally(onfinally?: (() => void) | undefined | null): Promise<T> {
    return promise.finally(onfinally);
}

then and finally are both correctly extracted (confirmed via function_data); catch — structurally identical, including the same generic-type-parameter shape then already handles fine post-#2219 — is silently dropped.

Root cause: LANGUAGE_DEFINITIONS["typescript"]["rules"]["func_start"] in gitgalaxy/standards/language_standards.py has a reserved-keyword negative lookahead (appearing at two points in the pattern) that excludes catch along with class|interface|enum|if|for|while|switch|return|throw|new|typeof|jQuery|function|yield|await|void:

(?!(?:class|interface|enum|if|for|while|switch|catch|return|throw|new|typeof|jQuery|function|yield|await|void)\b|type\b(?![ \t\n]*\()|\$)

This shield exists for a real reason — confirmed via direct regex testing that } catch (e) { (a genuine control-flow block) does NOT false-positive as a method definition, and removing catch from the exclusion list naively would very likely reopen that false-positive. But it also means catch used as a legitimate method name (any Promise/Thenable-shaped class, .catch()-alike APIs) can never be extracted, ever, regardless of generics/modifiers/context.

Confirmed scope: exactly 1 occurrence in the 23-file typescript corpus (language-crucible/data/typescript), via tri_comparison_gatherer.gather_language("typescript") name-diffed against tree-sitter across every file. ctags also misses it (confirmed via a direct ctags -x --languages=TypeScript --kinds-TypeScript=* vscode/async.ts run — no tag anywhere near line 74), so GitGalaxy is not uniquely at fault here, but it is still a real, verified false negative.

Why not fixed inline: distinguishing "method named catch" from "control-flow catch (e) {" from text shape alone needs real design work (e.g. requiring the preceding non-whitespace token be }+newline+no-modifier for the control-flow case vs. a class-body context for the method case) — not a safe one-line regex tweak, so filing rather than shipping a fix in the same pass, per this repo's tri-comparison-ledger-sweep skill's own scope discipline.

Activity

  1. added
    bug
    core-engine
    threat: false-negative
    on Aug 26, 2026
  2. squid-protocol commented on Aug 26, 2026

    @squid-protocol
    OwnerAuthor

    Second confirmed instance in the same sweep: vscode/async.ts:2511-2513, another reserved word in the same func_start exclusion list —

    private readonly _iterator: AsyncIterator<T, void, void> = {
        next: () => this._producerConsumer.consume(),
        return: () => {
            this._onReturn?.();
            return Promise.resolve({ done: true, value: undefined });
        },
        throw: async (e) => { ... },
    };

    return is a real, legitimate property name here (implementing the AsyncIterator protocol's return() method) — sitting on its own line, not comma-preceded, so this isn't the line-start issue (#2277); it's excluded purely because return is in the same negative-lookahead list as catch. next (not excluded) is found fine; throw is also in the exclusion list and worth checking too, though not separately confirmed here. Same fix-direction caveat applies: distinguishing return: () => {} (property) from a real return statement from text shape alone needs the same kind of design work as catch, not a blind removal from the exclusion list.

  3. added this to the v2.4.9 milestone on Aug 31, 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: mediumthreat: false-negative

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions