Skip to content

Bug: Angle Brackets as Math Operators Corrupt Depth Parsing #1853

Closed

Description

@squid-protocol

Bug: Angle Brackets as Math Operators Corrupt Depth Parsing

Description

In gitgalaxy/core/detector.py, the _count_top_level_args method blindly treats angle brackets < and > as scope delimiters to support generics (e.g., List<String>). However, these characters double as math operators (less-than, greater-than, left-shift).

elif ch in "([{<":
    depth += 1
elif ch in ")]}>":
    if ch == ">" and i > 0 and body[i - 1] in "=-":
        pass
    elif depth > 0:
        depth -= 1

Impact

When < or > is used as a math or comparison operator inside a default argument value, it corrupts the depth counter for the remainder of the parameter block:

  • Less-than operator (a = x < y): The < increments the depth counter permanently since there is no matching >. This causes all subsequent top-level commas to be ignored as if they were inside a generic bracket, resulting in severe undercounting.
  • Greater-than operator (a = (x > y, z)): The > prematurely decrements the depth counter. If it decrements the depth to 0, nested commas (like the one separating x > y and z) are exposed and erroneously counted as top-level argument separators, resulting in overcounting.

Steps to Reproduce

  1. Test with: def foo(a = (x < y), b = 2) -> Returns 1 argument (undercounted).
  2. Test with: def foo(a = (x > y, z), b = 2) -> Returns 3 arguments (overcounted).

Suggested Fix

Consider detecting whether < or > is part of a balanced generic block or surrounded by spaces/math structures to distinguish them from standard operators, or restrict their generic-bracket behavior solely to statically-typed languages.

Activity

  1. added
    bug
    core-engine
    testing
    on Aug 19, 2026
  2. squid-protocol commented on Aug 28, 2026

    @squid-protocol
    OwnerAuthor

    Fixed in #1884 (merged). Angle-bracket depth tracking in _count_top_level_args is now gated to _ANGLE_BRACKET_GENERIC_LANGUAGES (cpp/rust/csharp/java/kotlin/scala/typescript/swift/go/dart), so </> used as comparison/shift operators in a default value no longer corrupt the depth counter. Verified: def foo(a = (x < y), b = 2) and def foo(a = (x > y, z), b = 2) both return 2 now. Regression test test_count_top_level_args_angle_brackets_as_math_operators_1853 passes on current main.

    Note: the harder residual case — </> ambiguity inside a generic-using language's own default-value expressions — remains, as #1884 called out; that needs a type-aware parser. Opening a narrow follow-up only if it shows up in real corpus data.

  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: mediumtesting

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions