Skip to content

fix(csharp): recover same-scope arity-pair and partial-sibling INHERITS edges#774

Merged
vitali87 merged 4 commits into
mainfrom
fix/764-same-scope-arity-pairs
Jul 16, 2026
Merged

fix(csharp): recover same-scope arity-pair and partial-sibling INHERITS edges#774
vitali87 merged 4 commits into
mainfrom
fix/764-same-scope-arity-pairs

Conversation

@vitali87

Copy link
Copy Markdown
Owner

What

Fixes #764: all three same-scope arity-pair shapes now emit their INHERITS edge.

  1. Same-file pair, child first (ITtlStrategy : ITtlStrategy<object> + ITtlStrategy<TResult> in one file): the two types collide on natural qn and the second registers as a DUP_QN_MARKER variant. The base resolves to the child itself and the self-loop guard refused the edge. Now the sibling recovery consults function_registry.variants(natural_qn) first: the same-scope variants bucket holds exactly the file-scope declarations of that simple name, so the unique other type declaration IS the written sibling, whichever of the pair the child happens to be. A 3+ arity family stays conservatively refused.
  2. Same-file pair nested in a class (ExecuteParameters<T> : ExecuteParameters inside a test class): same mechanism, one nesting level down.
  3. Partial sibling ambiguity (PredicateBuilder : PredicateBuilder<object> where the generic is partial across two files): the recovery saw two candidate qns and refused. The existing csharp_partial_groups index already knows the parts are ONE type; when every in-package candidate sits in a single partial group, the recovery returns the deterministic representative (min).

The recovered edge targets a @line variant qn, which leaked into the eval's simple-name reduction (ExecuteParameters@132 vs the oracle's ExecuteParameters), so both cgr-side name-edge reducers in evals/cgr_graph.py now strip the marker — the same normalization dead_code.py already applies to leaf names.

Why the reversed order already worked

When the generic declares first it takes the bare qn and the child registers as the variant; the written base then resolves to the bare sibling at parse time and never hits the self-loop guard. A regression pin covers that order.

Validation

Strict RED → GREEN in commit history: the three shape tests fail on main (test(csharp): RED ...), then the parser fix turns them green; the eval-normalization RED (test(evals): RED ...) demonstrates the marker leak with the parser fix applied, then the reducer fix turns it green.

Polly L1, both frontends (treesitter and CSHARP_FRONTEND=hybrid):

edge before after
INHERITS tp 221, fp 0, fn 3 tp 224, fp 0, fn 0 (p=1.0, r=1.0)
IMPLEMENTS 1.0 / 1.0 1.0 / 1.0 (unchanged)

Full suite green.

@greptile-apps

greptile-apps Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes C# inheritance recovery for generic arity sibling types. The main changes are:

  • Recovers same-scope INHERITS edges when duplicate qualified-name variants identify a unique sibling.
  • Resolves partial generic siblings when all same-package candidates belong to one C# partial group.
  • Strips duplicate qualified-name markers from eval inheritance name-edge targets.
  • Adds tests for same-file, nested, reversed-order, partial-sibling, and eval-scoring cases.
  • Updates the editable package version in uv.lock.

Confidence Score: 5/5

Safe to merge with low risk.

No issues were identified. The parser change is limited to C# self-resolution recovery, ambiguity paths still avoid emitting guessed edges, and tests cover the reported recovery and scoring cases.

No files require special attention.

T-Rex T-Rex Logs

What T-Rex did

  • The transcript artifact shows the build attempted to configure cmake for pymgclient==1.5.1 and failed with cmake3 is not accessible and cmake is not accessible, blocking the test run.
  • Because execution was blocked before pytest could start, the PR validation result is inconclusive.

View all artifacts

T-Rex Ran code and verified through T-Rex

Important Files Changed

Filename Overview
codebase_rag/parsers/class_ingest/mixin.py Adds C# arity-sibling recovery for same-scope duplicate variants and partial-type groups without verified issues.
evals/cgr_graph.py Normalizes duplicate qualified-name markers out of inheritance name-edge targets in both graph reducers.
codebase_rag/tests/test_csharp_inheritance.py Adds tests for same-file child-first, nested generic child-first, reversed-order, and partial sibling arity-pair inheritance recovery.
codebase_rag/tests/test_csharp_structure_oracle.py Adds an eval regression proving duplicate qualified-name markers are stripped when scoring inherited base names.
uv.lock Updates the editable package version only.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant Parser as C# class ingest
participant Registry as function_registry
participant Partials as csharp_partial_groups
participant Graph as eval name-edge reducers

Parser->>Registry: Resolve deferred base
alt parent_qn equals child_qn
    Parser->>Registry: variants(natural_qn)
    Registry-->>Parser: same-scope duplicate qns
    alt exactly one sibling variant
        Parser-->>Parser: emit INHERITS to sibling
    else multiple same-package candidates
        Parser->>Partials: group candidates
        Partials-->>Parser: single partial group representative
        Parser-->>Parser: emit INHERITS to representative
    else ambiguous
        Parser-->>Parser: emit no edge
    end
end
Parser->>Graph: recovered target qn may include DUP_QN_MARKER
Graph-->>Graph: strip marker from simple base name for scoring
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
participant Parser as C# class ingest
participant Registry as function_registry
participant Partials as csharp_partial_groups
participant Graph as eval name-edge reducers

Parser->>Registry: Resolve deferred base
alt parent_qn equals child_qn
    Parser->>Registry: variants(natural_qn)
    Registry-->>Parser: same-scope duplicate qns
    alt exactly one sibling variant
        Parser-->>Parser: emit INHERITS to sibling
    else multiple same-package candidates
        Parser->>Partials: group candidates
        Partials-->>Parser: single partial group representative
        Parser-->>Parser: emit INHERITS to representative
    else ambiguous
        Parser-->>Parser: emit no edge
    end
end
Parser->>Graph: recovered target qn may include DUP_QN_MARKER
Graph-->>Graph: strip marker from simple base name for scoring
Loading

Reviews (1): Last reviewed commit: "fix(evals): strip dup-qn marker from gra..." | Re-trigger Greptile

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses issue #764 by improving the handling of C# arity pairs and partial generic siblings. It updates the class ingestion logic to correctly identify same-scope declarations and ensures that inheritance edges are correctly resolved by stripping the DUP_QN_MARKER during evaluation. Additionally, new tests were added to verify these scenarios, and the project version was updated. The review feedback suggests improving the readability and robustness of string manipulation logic in evals/cgr_graph.py by breaking down chained operations and adding guards for delimiters.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread evals/cgr_graph.py
Comment thread evals/cgr_graph.py
@sonarqubecloud

Copy link
Copy Markdown

@vitali87
vitali87 merged commit 8228410 into main Jul 16, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

C# same-scope arity pairs (Foo and Foo<T> in one file/class) collide on qualified name and lose their INHERITS edge

1 participant