Repository navigation
fix(csharp): give a generic and a non-generic type separate ids (#4249) - #4255
ayushcodes10 wants to merge 2 commits into
Conversation
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.
|
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. |
There was a problem hiding this comment.
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— impacttests/test_build.py— impacttests/test_cjs_module_extension.py— impacttests/test_cpp_nested_and_cli.py— impacttests/test_csharp_type_resolution.py— impact, changed-testtests/test_dotnet.py— impacttests/test_extract.py— impacttests/test_extract_php_closures.py— impacttests/test_import_extension_resolution.py— impacttests/test_indirect_call_block_scoped_shadow.py— impacttests/test_indirect_dispatch.py— impacttests/test_indirect_dispatch_assign_return.py— impacttests/test_indirect_dispatch_getattr.py— impacttests/test_js_exported_scalar_bindings.py— impacttests/test_languages.py— impacttests/test_multilang.py— impacttests/test_php_unparsed_casts.py— impacttests/test_python_inherited_method_calls.py— impacttests/test_python_underscore_resolution.py— impacttests/test_rationale.py— impacttests/test_ruby_resolution.py— impacttests/test_scala_context_bounds.py— impacttests/test_scala_self_type.py— impacttests/test_scala_top_level_binding.py— impacttests/test_scala_type_definition.py— impacttests/test_svelte_extraction.py— impacttests/test_swift_computed_properties.py— impacttests/test_swift_protocol_requirements.py— impacttests/test_trailing_newline_not_a_syntax_error.py— impacttests/test_ts_new_expression_calls.py— impacttests/test_typescript_module_extensions.py— impacttests/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).
#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]>
|
Landed in v0.9.83 via an authorship-preserving cherry-pick, so your commit is on |
Fixes #4249.
nameis just the bare identifier for a C# type declaration; atype_parameter_listis a separate sibling node, soEffectandEffect<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_listreference, soTween<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
Effectnode witheffects_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 genericEffect<T>node, not the non-generic one. Two new regression tests intests/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 thattree-sitter-language-packis actually installed in this environment — untouched by this change, not something this PR causes or fixes).