Skip to content

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

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugUnintended behavior or logic failure in the enginecore-engineModifications to the central physics and parsing enginepriority: mediumtestingUnit, integration, and E2E pipeline verification

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions