Skip to content

bug(core): Nested class boundaries truncate outer class scope #1040

Closed

Description

@squid-protocol

Problem

The class-scoping logic in gitgalaxy/core/detector.py (lines 532-557) is flat and non-nesting-aware. It uses a single regex to find all class/struct/interface/trait/enum declarations, then assigns each class's scope to run from its declaration to the next class declaration's start position (line 541):

end_idx = class_matches[i + 1].start() if i + 1 < len(class_matches) else len(code_stream)

Bug

When a class contains a nested/inner class declaration (legal in Java, C#, TypeScript, PHP, Kotlin, Dart, C++, Scala, etc.), the nested class's class keyword produces its own regex match. That match becomes class_matches[i+1] for the outer class, so the outer class's scope is truncated to end right where the nested class begins.

Consequence: Any method physically declared in the outer class after the nested class declaration gets silently excluded from the outer class's metrics. The method-linking loop (lines 560-584) does:

if cls["_start_line"] <= func.get("start_line", 0) <= cls["_end_line"]:

Methods declared after the nested class have start_line > cls["_end_line"], so they fail this check and are dropped entirely from:

  • method_count
  • state_entanglement
  • lcom_score

This corrupts every per-class metric the engine currently computes for any class containing a nested class — not just a future LCOM redesign.

Example

class Outer {
    void method1() { }
    
    class Inner {           // Outer's scope ends here in current logic
        void innerMethod() { }
    }
    
    void method2() { }      // SILENTLY DROPPED from Outer's method_count
}

Fix Location

  • Class scoping logic: gitgalaxy/core/detector.py lines 532-557
  • Method-linking loop: gitgalaxy/core/detector.py lines 560-584

Fix Direction

A real fix needs brace/indent-depth-aware scope tracking (not simple "until next match") similar to how the engine already tracks nesting depth elsewhere for other constructs. The current flat assignment strategy cannot handle nested class declarations.

Blocking

This is a standalone correctness bug affecting current method_count/state_entanglement output today for any class with a nested class inside it, and is also a blocking prerequisite for issue #1018 (LCOM redesign).

Testing

No existing test coverage found for nested class declarations in the class-scoping logic.

Activity

  1. added
    bug
    data-integrity
    core-engine
    on Aug 4, 2026
  2. 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-enginedata-integrity

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions