Repository navigation
fix(csharp): never let a call bind to a same-named enum member (#4245) - #4254
ayushcodes10 wants to merge 2 commits into
Conversation
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.
|
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.
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— impacttests/test_astro_import_ids.py— impacttests/test_blade_extractor.py— impacttests/test_build.py— impacttests/test_builtin_global_type_refs.py— impacttests/test_cache.py— impacttests/test_case_sensitive_resolution.py— impacttests/test_cjs_module_extension.py— impacttests/test_cobol_extractor.py— impacttests/test_cpp_method_declarations.py— impacttests/test_cpp_nested_and_cli.py— impacttests/test_cpp_objc_cross_file_calls.py— impacttests/test_cross_extension_reexport_self_cycle.py— impacttests/test_cross_language_call_resolution.py— impacttests/test_cross_repo_external_call_guards.py— impacttests/test_cross_repo_member_calls.py— impacttests/test_csharp_call_site_generic_args.py— impacttests/test_csharp_enum_members.py— impact, changed-testtests/test_csharp_field_generic_args.py— impacttests/test_csharp_generic_callsites.py— impacttests/test_csharp_interface_dispatch.py— impacttests/test_csharp_member_calls.py— impacttests/test_csharp_member_nodes.py— impacttests/test_csharp_object_creation.py— impacttests/test_csharp_partial_classes.py— impacttests/test_csharp_tuple_type_refs.py— impacttests/test_csharp_type_resolution.py— impacttests/test_definition_file_portability.py— impacttests/test_detect.py— impacttests/test_dotnet.py— impacttests/test_duplicate_annotation_edges.py— impacttests/test_elixir_import_resolution.py— impacttests/test_elixir_keyword_def_calls.py— impacttests/test_elixir_qualified_calls.py— impacttests/test_elixir_unqualified_call_scope.py— impacttests/test_erlang_extractor.py— impacttests/test_extract.py— impacttests/test_extract_cache_location.py— impacttests/test_extract_path_memo.py— impacttests/test_extract_php_closures.py— impacttests/test_file_label_disambiguation.py— impacttests/test_file_node_id_spec.py— impacttests/test_forwarding_review_findings.py— impacttests/test_go_builtin_call_targets.py— impacttests/test_go_import_repoint.py— impacttests/test_go_interface_methods.py— impacttests/test_go_qualified_resolution.py— impacttests/test_import_extension_resolution.py— impacttests/test_import_self_loops.py— impacttests/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).
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]>
|
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 |
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
callsedge 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:
graphify/extractors/engine.py's per-filelabel_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 acase_ofedge (the relation every one of those languages already emits per enum case).graphify/extract.pyalready excludes acase_of/definestarget as a candidate — but only forrc.get("csharp_new")(whatnew X()constructs), not for an ordinary C# call. Widened the same exclusion to any C# call.Also threaded an optional
edgesparameter throughsymbol_resolution.build_label_index(defaulting toNone, so its two existing call sites with justnodesare 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_oftargets only (notdefines/property targets) for the per-file map, since the three repro shapes in the issue are all enum cases, and adefinestarget 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-namedState.Pauseenum member elsewhere in the corpus, confirming the fix doesn't make a genuine call unresolved). Two new regression tests intests/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).