Skip to content

fix(csharp): resolve calls through casts and interface-typed properties - #4172

Closed
Mpasha17 wants to merge 1 commit into
Graphify-Labs:v8from
Mpasha17:fix/csharp-calls-3797
Closed

Mpasha17 wants to merge 1 commit into
Graphify-Labs:v8from
Mpasha17:fix/csharp-calls-3797

Conversation

@Mpasha17

@Mpasha17 Mpasha17 commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Part of #3797. Two of the dropped C# call shapes from the issue:

  • ((IStore)_obj).Save() / (_obj as IStore).Save() got no calls edge. The receiver capture didn't handle a parenthesized cast, so the call never reached the member resolver. The cast's type is now used as the receiver, so it resolves like IStore.Save().
  • IStore Store => ...; Store.Save() resolved to the concrete Store.Save(), because a capitalised receiver was looked up as a type name first. A field/property/local of that name shadows the type in C#, so the recorded receiver_type is now tried first, with the type-name lookup as fallback.

The ?. case was already fixed by #3976.

Left out the partial-class case: it only misses when another class has a method with the same name, and fixing it (~8 lines) changes how every unqualified C# call gets resolved, so it felt riskier. Happy to send it as a separate PR if you want it.

Testing: 3 new tests in tests/test_csharp_member_calls.py (cast, as cast, property shadowing a type name), all fail on v8. Full suite on 3.10/3.12/3.13/3.14 with all extras: same failures as v8 on every version (only the existing test_dm_* / tree-sitter-dm, wheel-payload and known-flaky ones), plus the 3 new passes. ruff clean, pyright error count unchanged on the touched files. Live with graphify update --no-cluster on the issue's repro plus an as variant: v8 has Run -> Store.Save() and nothing for (_obj as IStore).Save(); this branch has Run -> IStore.Save() and RunAs -> IStore.Save(), no other edges changed.

AI-assisted (Grok Bot); each commit carries a Co-Authored-By line.

…es (Graphify-Labs#3797)

((IStore)_obj).Save() and (_obj as IStore).Save() produced no calls edge:
the receiver capture didn't handle a parenthesized cast, so the call never
reached the receiver-typed resolver. Use the cast's type as the receiver so
it resolves like IStore.Save().

IStore Store => ...; Store.Save() bound to the concrete Store.Save() because
a capitalised receiver was looked up as a type name first. A field, property
or local of that name shadows the type, so try the recorded receiver_type
first and fall back to the type name.

Co-Authored-By: Grok Bot <[email protected]>
@Mpasha17
Mpasha17 requested a review from safishamsi as a code owner October 6, 2026 16:58
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown

Thanks for the pull request, @Mpasha17. 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 1 advisory finding(s) below merit a look before merge.

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

Not verified on this run: \_resolve\_csharp\_member\_calls (vacuous: never exercised), \_extract\_generic (unsupported).


Graphify review — findings

Fixes C# member-call resolution so a Pascal-cased receiver that names a field, property, or local in scope resolves to that member's declared type. For example, IStore Store => ...; Store.Save() now links to IStore.Save, not the class Store's method, and it falls back to treating the receiver as a type name only when no declared type is known. Cast receivers like ((IStore)x).Save() and (x as IStore).Save() also resolve against the cast type, with tests covering all three cases (#3797).

Worth a look

  • Unresolved shadow receiver falls back to same-named type — graphify/extract.py:4689 · 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 — 2769 functions depend on the 611 functions this change touches.

Health — this change adds coupling hotspots:

  • new: extract() — 778 callers, 50 callees
  • new: _rebuild_code() — 149 callers, 56 callees
  • new: _extract_generic() — 18 callers, 31 callees
  • new: extract_js() — 87 callers, 4 callees
  • new: extract_xaml() — 19 callers, 17 callees
  • new: main() — 102 callers, 3 callees
  • new: dispatch_command() — 2 callers, 128 callees
  • new: extract_objc() — 27 callers, 9 callees
  • …and 48 more — each is listed as a finding

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

Test selection

Test selection

147 of 334 test file(s) selected (44%) 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
  • 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, changed-test
  • 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_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_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
  • tests/test_incremental.py — impact
  • tests/test_indirect_call_arrow_single_param_shadow.py — impact
  • tests/test_indirect_call_block_scoped_shadow.py — impact
  • … and 97 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 \_resolve\_csharp\_member\_calls.

The verifier did not have enough to check \_resolve\_csharp\_member\_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

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

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

@Mpasha17

Mpasha17 commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Checked this one live: with IRemoteStore Store => null; (type not in the corpus) plus a local class Store, Store.Save() binds to Store.Save on clean v8 too, so it's existing behaviour, not something this PR introduced (the full edge lists are identical before/after). The fallback to the type name is kept on purpose, since that's what makes plain static calls like Store.Save() resolve when there's no member named Store in scope. This PR only changes the order, trying the member's declared type first when it resolves.

@safishamsi

Copy link
Copy Markdown
Member

Landed in v0.9.78 via an authorship-preserving cherry-pick (your commit is on v8 with you as the author). Closing as shipped — thanks @Mpasha17!

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.

2 participants