Skip to content

fix(csharp): give a generic and a non-generic type separate ids (#4249) - #4255

Closed
ayushcodes10 wants to merge 2 commits into
Graphify-Labs:v8from
ayushcodes10:fix-4249-csharp-generic-type-arity
Closed

ayushcodes10 wants to merge 2 commits into
Graphify-Labs:v8from
ayushcodes10:fix-4249-csharp-generic-type-arity

Conversation

@ayushcodes10

Copy link
Copy Markdown
Contributor

Fixes #4249.

name is just the bare identifier for a C# type declaration; a type_parameter_list is a separate sibling node, so Effect and Effect<T> minted the exact same id and merged into one node. The common base-pair shape (Effect<T> : Effect, Comparer<T> : Comparer) then showed as a self-loop, and any member declared on the generic landed on the same node as the non-generic one.

Folds the declared arity into the id the same way C# metadata itself names a generic type (Effect`1), so each arity gets its own node. The label is untouched (still just "Effect"), and a non-generic declaration (arity 0) keeps today's id exactly — no change for the overwhelmingly common case.

Also extended the same arity-awareness to a same-file base_list reference, so Tween<T> : Effect<T> (both in the same file) resolves to a real definition rather than a dangling stub or, worse, the unrelated non-generic sibling.

Disclosed limitation, not fixed here: the cross-file type index this extractor shares with ordinary type references (_build_csharp_type_def_index / CsharpNameResolver, from #3795/#3815) still picks one arbitrary candidate when more than one same-named definition exists for a namespace — it has no arity concept at all. So a generic subtype whose same-named generic base lives in a different file may still resolve to the wrong arity sibling rather than failing to resolve outright. Making that shared index arity-aware would mean adding arity to node metadata and threading a desired-arity parameter through every one of its callers (field/property/parameter/return type references, qualified calls, aliasing) — a meaningfully larger change I didn't want to risk alongside this fix. The node collapse and the resulting self-loop — the actual reported defect — are fixed regardless, in both the same-file and cross-file case (the nodes are always separate now; only which specific cross-file sibling an edge names can still be imprecise).

Verified against the issue's exact repro: before, one Effect node with effects_demo_effect --inherits--> effects_demo_effect (self-loop). After, two nodes and no self-loop; Tween<T>'s inherits edge (same file) correctly reaches the generic Effect<T> node, not the non-generic one. Two new regression tests in tests/test_csharp_type_resolution.py, confirmed to fail against pre-fix code. Full suite passes clean with correct module resolution (one unrelated, pre-existing Erlang cross-file-call gap is visible now that tree-sitter-language-pack is actually installed in this environment — untouched by this change, not something this PR causes or fixes).

name is just the bare identifier for a C# type declaration; a type
parameter list is a separate sibling node, so Effect and Effect of T
minted the exact same id and merged into one node. A common base pair
shape (Effect of T inherits Effect, Comparer of T inherits Comparer)
then showed as a self loop, and any member declared on the generic
landed on the same node as the non generic one.

Fold the declared arity into the id the same way C# metadata itself
names a generic type, so each arity gets its own node; the label is
untouched, and a non generic declaration (arity zero) keeps today's
id exactly. Extend the same arity awareness to a same file base list
reference, so a generic subtype inheriting a same named generic base
in the same file reaches a real definition rather than a dangling
stub or, worse, the unrelated non generic sibling.

A separate, narrower limitation remains and is not fixed here: the
cross file type index this extractor shares with ordinary type
references still picks one arbitrary candidate when more than one
same named definition exists for a namespace, so a generic subtype
whose same named generic base lives in a DIFFERENT file may still
resolve to the wrong arity sibling rather than failing to resolve at
all. The node collapse and the resulting self loop, the actual
reported defect, are fixed regardless.

Fixes Graphify-Labs#4249.
Covers the exact shape from the issue, a generic and a non generic
type of the same name getting separate nodes with no self loop, plus
a control confirming two unrelated same named types in different
namespaces were already correctly separate and stay that way.
Confirmed to fail against pre fix code; the control passes either way.
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown

Thanks for the pull request, @ayushcodes10. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic.

@graphify-labs graphify-labs Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Graphify reviewed this change.

Worth a look — the grounded gate found no coupling regressions or blocking issues, but 2 advisory finding(s) below merit a look before merge.


Graphify review — findings

Fixes C# generic and non-generic types of the same name (Effect / Effect<T>) merging into one node by folding the type-parameter arity into the node id (Effect`1), so Effect<T> : Effect no longer becomes a self-loop. Labels and non-generic ids stay unchanged. Base references with type arguments resolve to the matching arity-suffixed node when it exists in the same file, and otherwise fall back to the existing bare-name lookup and stub.

Worth a look

  • Generic C# declarations get arity-suffixed ids but ordinary type references still target the bare name — graphify/extractors/engine.py:4823 · Escalate · medium · 2 independent checks
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
  • Qualified generic C# base names do not participate in arity-based base resolution — graphify/extractors/engine.py:5219 · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 882 functions depend on the 340 functions this change touches.

Health — this change adds coupling hotspots:

  • new: _extract_generic() — 19 callers, 34 callees
  • new: extract_js() — 87 callers, 5 callees
  • new: extract_xaml() — 19 callers, 17 callees
  • new: extract_objc() — 27 callers, 10 callees
  • new: extract_php() — 37 callers, 5 callees
  • new: extract_cpp() — 36 callers, 5 callees
  • new: extract_julia() — 19 callers, 8 callees
  • new: extract_svelte() — 14 callers, 8 callees
  • …and 11 more — each is listed as a finding

Verification — 882 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 783 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

32 of 355 test file(s) selected (9%) via static blast radius.

  • tests/test_astro_extraction.py — impact
  • tests/test_build.py — impact
  • tests/test_cjs_module_extension.py — impact
  • tests/test_cpp_nested_and_cli.py — impact
  • tests/test_csharp_type_resolution.py — impact, changed-test
  • tests/test_dotnet.py — impact
  • tests/test_extract.py — impact
  • tests/test_extract_php_closures.py — impact
  • tests/test_import_extension_resolution.py — impact
  • tests/test_indirect_call_block_scoped_shadow.py — impact
  • tests/test_indirect_dispatch.py — impact
  • tests/test_indirect_dispatch_assign_return.py — impact
  • tests/test_indirect_dispatch_getattr.py — impact
  • tests/test_js_exported_scalar_bindings.py — impact
  • tests/test_languages.py — impact
  • tests/test_multilang.py — impact
  • tests/test_php_unparsed_casts.py — impact
  • tests/test_python_inherited_method_calls.py — impact
  • tests/test_python_underscore_resolution.py — impact
  • tests/test_rationale.py — impact
  • tests/test_ruby_resolution.py — impact
  • tests/test_scala_context_bounds.py — impact
  • tests/test_scala_self_type.py — impact
  • tests/test_scala_top_level_binding.py — impact
  • tests/test_scala_type_definition.py — impact
  • tests/test_svelte_extraction.py — impact
  • tests/test_swift_computed_properties.py — impact
  • tests/test_swift_protocol_requirements.py — impact
  • tests/test_trailing_newline_not_a_syntax_error.py — impact
  • tests/test_ts_new_expression_calls.py — impact
  • tests/test_typescript_module_extensions.py — impact
  • tests/test_vue_extraction.py — impact

Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.

· 19 more finding(s) on lines outside this diff (see the check run).

safishamsi pushed a commit that referenced this pull request Oct 9, 2026
#4249)

Fold the type-parameter arity into the C# type node id (Effect`1), so Effect
and Effect<T> no longer collapse to one node and Effect<T> : Effect stops
producing an inherits self-loop. Arity 0 keeps the current id (back-compat);
backtick is collision-free and deterministic.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Landed in v0.9.83 via an authorship-preserving cherry-pick, so your commit is on v8 with you credited as the author. Closing as shipped — thanks @ayushcodes10!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: C#: a generic and a non-generic type of the same name share one node

2 participants