Skip to content

fix(csharp): never let a call bind to a same-named enum member (#4245) - #4254

Closed
ayushcodes10 wants to merge 2 commits into
Graphify-Labs:v8from
ayushcodes10:fix-4245-csharp-enum-member-call-binding
Closed

ayushcodes10 wants to merge 2 commits into
Graphify-Labs:v8from
ayushcodes10:fix-4245-csharp-enum-member-call-binding

Conversation

@ayushcodes10

Copy link
Copy Markdown
Contributor

Fixes #4245.

#3795 is fixed for TYPE references (a base type or parameter type no longer resolves to a same-named enum member). Calls still could. The reported shape: invoking a delegate-typed field whose name happens to match one of its own enum's cases got a calls edge to the case instead of no edge — an enum member can never be the target of a call.

Traced this to two separate places, neither of which had the exclusion #3795 already applies for type lookup:

  1. graphify/extractors/engine.py's per-file label_to_nid — the shared bare-name-to-node map used by Ruby, C#, Java, Kotlin and more (per its own comment) to resolve a same-file call. No exclusion for a node that's the target of a case_of edge (the relation every one of those languages already emits per enum case).
  2. The shared cross-file call resolver in graphify/extract.py already excludes a case_of/defines target as a candidate — but only for rc.get("csharp_new") (what new X() constructs), not for an ordinary C# call. Widened the same exclusion to any C# call.

Also threaded an optional edges parameter through symbol_resolution.build_label_index (defaulting to None, so its two existing call sites with just nodes are untouched) so it can apply the same exclusion when edges are available — kept for symmetry with the other two fixes even though the live pipeline doesn't currently route through that function.

Scoped to case_of targets only (not defines/property targets) for the per-file map, since the three repro shapes in the issue are all enum cases, and a defines target can legitimately be a callable variable in some other language that shares this same per-file map (e.g. a JS/Dart arrow function assigned to a variable) — didn't want to guess at a broader exclusion without a concrete failing case for it.

Verified against the issue's exact repro (the Delegate(t) case) and a control case (Handles[i].Pause() against a same-named State.Pause enum member elsewhere in the corpus, confirming the fix doesn't make a genuine call unresolved). Two new regression tests in tests/test_csharp_enum_members.py, confirmed to fail against pre-fix code (the control passes either way). Full suite passes clean with no failures at all once run with the correct module resolution (confirmed the one run that showed 26 failures was the editable-install trap — subprocess-based tests picking up a different checkout — not a real regression).

An enum member can never be the target of a call, in any language
sharing the per file label index (Ruby, C#, Java, Kotlin and more all
reach it) or the cross file symbol index (build_label_index), yet
neither excluded one. A bare call whose name happened to match a same
named enum case bound to the case instead of to a real method or
getting no edge at all, for example a delegate typed field invoked
right next to an enum sharing its name.

Exclude the target of any case_of edge from both indexes, mirroring
the exclusion the C# type definition index already applies for type
lookup. Also widen an existing, narrower exclusion in the shared cross
file call resolver that already dropped an enum member or a field or
property as a candidate for what a C# new X() constructs, so a plain
C# call gets the same treatment, not only a construction call.

Fixes Graphify-Labs#4245.
Covers the exact shape from the issue, a delegate typed field invoked
next to an enum sharing its name getting no calls edge to the case,
plus a control confirming an element access member call on a same
named enum elsewhere in the corpus still resolves to the real method.
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.

Formal verification. PR-changed functions: 0/4 verified (0 proven, 0 may-equivalent, 0 distinguished) · 4 not verified (2 vacuous, 2 unsupported).

Not verified on this run: extract (vacuous: never exercised), \_extract\_generic (unsupported), build\_label\_index (unsupported), resolve\_cross\_file\_raw\_calls (vacuous: never exercised).


Graphify review — findings

Stops call resolution from binding a bare call to a same-named enum member (#4245). For example, a delegate-typed field Delegate(t) sitting next to enum Kind { …, Delegate } now gets no calls edge to the case instead of a wrong one. _extract_generic's label map and build_label_index (when passed edges, as resolve_cross_file_raw_calls now does) both skip case_of targets, and C# call resolution filters out enum/field/property nodes for every call rather than only new X().

Worth a look

  • Enum cases with associated values or parameters are now unresolvable call targets — graphify/extractors/engine.py:6919 · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
  • Regression test checks the wrong enum member — tests/test_csharp_enum_members.py:184 · 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 — 2967 functions depend on the 611 functions this change touches.

Health — this change adds coupling hotspots:

  • new: extract() — 819 callers, 51 callees
  • new: _rebuild_code() — 162 callers, 56 callees
  • new: _extract_generic() — 19 callers, 34 callees
  • new: extract_js() — 87 callers, 5 callees
  • new: extract_xaml() — 19 callers, 17 callees
  • new: main() — 102 callers, 3 callees
  • new: extract_objc() — 27 callers, 10 callees
  • new: dispatch_command() — 2 callers, 130 callees
  • …and 54 more — each is listed as a finding

Verification — 2967 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: 2772 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

160 of 355 test file(s) selected (45%) via static blast radius.

  • tests/test_astro_extraction.py — impact
  • tests/test_astro_import_ids.py — impact
  • tests/test_blade_extractor.py — impact
  • tests/test_build.py — impact
  • tests/test_builtin_global_type_refs.py — impact
  • tests/test_cache.py — impact
  • tests/test_case_sensitive_resolution.py — impact
  • tests/test_cjs_module_extension.py — impact
  • tests/test_cobol_extractor.py — impact
  • tests/test_cpp_method_declarations.py — impact
  • tests/test_cpp_nested_and_cli.py — impact
  • tests/test_cpp_objc_cross_file_calls.py — impact
  • tests/test_cross_extension_reexport_self_cycle.py — impact
  • tests/test_cross_language_call_resolution.py — impact
  • tests/test_cross_repo_external_call_guards.py — impact
  • tests/test_cross_repo_member_calls.py — impact
  • tests/test_csharp_call_site_generic_args.py — impact
  • tests/test_csharp_enum_members.py — impact, changed-test
  • tests/test_csharp_field_generic_args.py — impact
  • tests/test_csharp_generic_callsites.py — impact
  • tests/test_csharp_interface_dispatch.py — impact
  • tests/test_csharp_member_calls.py — impact
  • tests/test_csharp_member_nodes.py — impact
  • tests/test_csharp_object_creation.py — impact
  • tests/test_csharp_partial_classes.py — impact
  • tests/test_csharp_tuple_type_refs.py — impact
  • tests/test_csharp_type_resolution.py — impact
  • tests/test_definition_file_portability.py — impact
  • tests/test_detect.py — impact
  • tests/test_dotnet.py — impact
  • tests/test_duplicate_annotation_edges.py — impact
  • tests/test_elixir_import_resolution.py — impact
  • tests/test_elixir_keyword_def_calls.py — impact
  • tests/test_elixir_qualified_calls.py — impact
  • tests/test_elixir_unqualified_call_scope.py — impact
  • tests/test_erlang_extractor.py — impact
  • tests/test_extract.py — impact
  • tests/test_extract_cache_location.py — impact
  • tests/test_extract_path_memo.py — impact
  • tests/test_extract_php_closures.py — impact
  • tests/test_file_label_disambiguation.py — impact
  • tests/test_file_node_id_spec.py — impact
  • tests/test_forwarding_review_findings.py — impact
  • tests/test_go_builtin_call_targets.py — impact
  • tests/test_go_import_repoint.py — impact
  • tests/test_go_interface_methods.py — impact
  • tests/test_go_qualified_resolution.py — impact
  • tests/test_import_extension_resolution.py — impact
  • tests/test_import_self_loops.py — impact
  • tests/test_imported_export_forwarding.py — impact
  • … and 110 more

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.

Formal verification

Could not verify: Could not verify extract.

The verifier did not have enough to check extract, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: not verifiable: all 90 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly TypeError — names the real obstacle, not a sampling gap)

Could not verify: Could not verify \_extract\_generic.

The verifier did not have enough to check \_extract\_generic, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: parameter `config` is annotated `LanguageConfig` — outside the synthesizable primitive/collection set

Could not verify: Could not verify build\_label\_index.

The verifier did not have enough to check build\_label\_index, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: parameter `edges` is annotated `'list[dict[str, Any]] | None'` — outside the synthesizable primitive/collection set

Could not verify: Could not verify resolve\_cross\_file\_raw\_calls.

The verifier did not have enough to check resolve\_cross\_file\_raw\_calls, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: non-vacuity: domain too small (only 1 distinct inputs exercised, need 3) — 'no divergence' would be near-vacuous

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

safishamsi pushed a commit that referenced this pull request Oct 9, 2026
Exclude case_of targets from the per-file label map and apply the cross-file
_member_nids exclusion to all C# calls (not only new X()), so a bare call like
Delegate(t) no longer binds to a same-named enum case. Methods are method/
contains targets, not defines, so real call targets survive; fail-closed.

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. One small maintainer tweak: I tightened the repro test to pin the enum member named Delegate (the enum also has Linear), so it reliably exercises the collision rather than depending on set-iteration order. 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.

C#: calls bind to enum members of the same name (follow-up to #3795)

2 participants