Skip to content

tree_sitter_accuracy_audit.py's _get_param_count undercounts cpp functions with default parameters #2014

Closed

Description

@squid-protocol

Summary

During the tri-comparison-ledger-sweep (GitGalaxy vs. ctags vs. tree-sitter) investigating C++ parameter-counting accuracy, a systematic bias emerged in tree-sitter's parameter measurements: tree-sitter consistently undercounts by exactly 1 whenever a function parameter has a default value.

Verified pattern: Tree-sitter's parameter count is off-by-one lower in every sampled case where a function has a defaulted parameter:

Function Source ctags GitGalaxy tree-sitter Real param count
save_scene_to_path godot/editor_node.h 2 2 1 2 ✓
step godot/editor_node.h:1055 1 1 0 1 (default: int p_step = -1) ✓
get_index godot/node.h:590 1 1 0 1 (default: bool p_include_internal = true) ✓
atr_n godot/node.h 4 4 3 4 (has defaulted param) ✓
atr godot/node.h 2 2 1 2 (has defaulted param) ✓
ObjectSignalLock godot/object.cpp 2 2 1 2 (has defaulted param) ✓

In every case, ctags and GitGalaxy agree on the correct count (verified by reading source), and tree-sitter is exactly 1 lower.

Corpus: language-crucible/data/cpp/ (6+ confirmed examples as of 2026-08-21).

Impact

  • Parameter counting is a core verification signal in tests/tools/tree_sitter_accuracy_audit.py and tests/tools/tri_comparison_gatherer.py, used to generate the tri-comparison ledger.
  • This systematic undercount biases all cpp/function/args comparisons where defaults are present, making tree-sitter appear systematically worse than it actually is (a measurement artifact, not a real accuracy difference).
  • Any follow-up work relying on tree-sitter's cpp parameter counts as ground truth will inherit this bias.

Suggested fix

The issue is in tests/tools/tree_sitter_accuracy_audit.py's _get_param_count() function, which handles per-language parameter enumeration. The cpp-specific logic enumerates parameter node types but appears to miss the node type wrapping a parameter with a default value.

  1. Locate the cpp-specific parameter-list walking logic in _get_param_count().
  2. Parse a simple test case (void f(int x = 0)) directly with tree-sitter-cpp to inspect the actual node type/shape for defaulted parameters (likely something like optional_parameter_declaration or similar in tree-sitter-cpp's grammar).
  3. Update the cpp parameter-enumeration logic to include the missing node type.
  4. Verify the fix against the 6 known failing cases in the corpus.
  5. Check whether the same pattern affects other languages with default parameters (e.g., C, Java, Rust) — this issue was found investigating cpp but the root cause is likely language-agnostic.

Note: This is specifically a bug in the VERIFICATION TOOLING, not GitGalaxy production code — ctags and GitGalaxy both already count these correctly.

Cross-reference

Activity

  1. added
    bug
    testing
    on Aug 21, 2026
  2. 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

    bugtesting

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions