Skip to content

feat(csharp): register operators, conversion operators, and finalizers as member nodes#728

Open
vitali87 wants to merge 1 commit into
mainfrom
feat/csharp-operator-dtor-nodes
Open

feat(csharp): register operators, conversion operators, and finalizers as member nodes#728
vitali87 wants to merge 1 commit into
mainfrom
feat/csharp-operator-dtor-nodes

Conversation

@vitali87

Copy link
Copy Markdown
Owner

What

Closes a known C# Phase-1 gap: operator overloads, conversion operators, and finalizers (destructors) now register as member nodes.

  • Operators (operator +) and conversion operators (implicit/explicit operator T) have no name field in tree-sitter-c-sharp 0.23.5, so ingest_method dropped them. They now get a synthesized leaf: operator_<symbol> / operator_<target-type>, plus the parameter signature so overloaded operators (operator +(Vec,Vec) vs operator +(Vec,int)) stay distinct nodes.
  • Finalizers (~Foo) do have a name field equal to the type name, which collided with the constructor; they are now prefixed with ~.
  • The synthesis is centralized in csharp.utils.synthesize_method_name and shared by _csharp_get_name (FQN scope walk), extract_method_signature, and ingest_method, so the scope walk and the registered node qn agree.

Dead-code correctness

Now that these register, an unused operator (invoked by a + b syntax) or finalizer (invoked by the GC) would surface as a false-positive dead-code hit. Added _is_csharp_operator_or_finalizer_root (mirrors the existing C++ operator root) so both are reachability roots on .cs files.

Tests (red → green)

  • test_members_generics_and_operators / test_operator_overloads_and_conversions_are_distinct: operators, conversion operators (by target type), and finalizers register with the right names and distinct overload signatures.
  • test_operator_and_finalizer_are_roots: neither is reported dead without an incoming CALLS edge.

Full suite: 5022 passed, 10 skipped. ruff + ty clean.

@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 introduces support for C# operator overloads, conversion operators, and destructors/finalizers. It ensures these elements are correctly named, registered as members, and treated as reachability roots in dead code analysis since they are invoked via syntax or the garbage collector rather than explicit named calls. Corresponding unit tests have been added to verify these behaviors. There are no review comments, so no feedback is provided.

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.

@greptile-apps

greptile-apps Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds C# member registration for operators, conversion operators, and finalizers. The main changes are:

  • Synthesized C# member names for operator overloads, conversion operators, and finalizers.
  • Shared synthesized naming between FQN resolution, method signature extraction, and ingestion.
  • Dead-code root handling for C# operators and finalizers invoked outside normal named calls.
  • Tests for distinct operator overloads, conversion operators, finalizers, and dead-code reachability.

Confidence Score: 5/5

Safe to merge with minimal risk.

The change is narrowly scoped and keeps synthesized naming consistent across FQN resolution, signature extraction, ingestion, and dead-code handling. Targeted tests cover the changed C# definition and reachability behavior. No review issues were identified.

No files require special attention.

T-Rex T-Rex Logs

What T-Rex did

  • T-Rex ran the targeted tests without the CLI shim and hit a setup blocker, collecting the three requested tests before failing with an AttributeError for missing codebase_rag.cli.
  • T-Rex introduced a helper shim to bypass the local dependency-driven CLI import blocker.
  • T-Rex re-ran the targeted tests with the CLI shim and observed a successful run: 3 passed, 1 warning in 0.93s.
  • Artifacts were prepared for review, including the unshimmed run log, the shim-enabled run log, and the generated sitecustomize shim.

View all artifacts

T-Rex Ran code and verified through T-Rex

Important Files Changed

Filename Overview
codebase_rag/dead_code.py Marks synthesized C# operators and finalizers as dead-code roots for .cs methods, consistent with runtime/operator-syntax invocation.
codebase_rag/language_spec.py Routes C# FQN name resolution for operators, conversion operators, and destructors through the shared synthesized-name helper.
codebase_rag/parsers/csharp/utils.py Centralizes C# synthesized method names and uses them in signature extraction so overloaded operators and destructors register consistently.
codebase_rag/parsers/utils.py Updates method ingestion to use synthesized C# member names before registering method nodes.
codebase_rag/tests/test_csharp_dead_code.py Adds coverage that C# operators and finalizers are not reported as dead code when they lack incoming call edges.
codebase_rag/tests/test_csharp_definitions.py Adds C# definition tests for operator overloads, conversion operators, and finalizers with distinct qualified names.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant Parser as C# tree-sitter node
participant Synth as csharp.utils.synthesize_method_name
participant FQN as language_spec._csharp_get_name
participant Ingest as parsers.utils.ingest_method
participant Graph as Graph method node
participant Dead as dead_code roots

Parser->>Synth: operator/conversion/finalizer node
Synth-->>FQN: synthesized scope leaf
Synth-->>Ingest: registered method leaf
Ingest->>Graph: method qn with signature when needed
Graph->>Dead: candidate method
Dead->>Dead: root if `.cs` and leaf starts `operator_` or `~`
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# tree-sitter node
participant Synth as csharp.utils.synthesize_method_name
participant FQN as language_spec._csharp_get_name
participant Ingest as parsers.utils.ingest_method
participant Graph as Graph method node
participant Dead as dead_code roots

Parser->>Synth: operator/conversion/finalizer node
Synth-->>FQN: synthesized scope leaf
Synth-->>Ingest: registered method leaf
Ingest->>Graph: method qn with signature when needed
Graph->>Dead: candidate method
Dead->>Dead: root if `.cs` and leaf starts `operator_` or `~`
Loading

Reviews (1): Last reviewed commit: "feat(csharp): register operators, conver..." | Re-trigger Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant