Skip to content

fix(csharp): never bind a nameless member-call receiver to a same-named method in the file - #4422

Closed
nixvideojuego-ui wants to merge 1 commit into
Graphify-Labs:v8from
nixvideojuego-ui:fix/csharp-untyped-receiver-fallback
Closed

nixvideojuego-ui wants to merge 1 commit into
Graphify-Labs:v8from
nixvideojuego-ui:fix/csharp-untyped-receiver-fallback

Conversation

@nixvideojuego-ui

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #4418.

A C# member call whose receiver has no capturable name reached the per-file bare-name map, because the C# defer rule required member_receiver. This covers a member chain (run.Sequence.Apply(), s.Items.Count()), an invocation (Pick().look.LateUpdate()) and a new X(...).M(). The call then bound to the caller's own same-named method as an EXTRACTED edge:

Changes:

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Tests or CI
  • Refactor
  • Security fix

Verification & Invariants

Invariant: a C# member call binds by receiver evidence or not at all. A same-file method that only shares the name is never evidence.

  • Read the CONTRIBUTING.md guide.
  • Reproduced the issue and identified the invariant.
  • Made the smallest fix necessary.
  • Added a regression test: 3 tests in tests/test_csharp_member_chain_calls.py. All 3 fail on v8 (e8eb76e) and pass here.
  • Kept the PR description synchronized with the final implementation.
  • Documented any limitations / unsupported cases explicitly.

Limitations (recall trade, like the Python #2586 note): a call that only resolved through the name collision now gets no edge. Typical cases:

  • an extension method invoked on a chained receiver (component.gameObject.GetAsyncX() landing on a same-named overload in the same static class);
  • a new X<T>().M() whose bare X names both a generic and a non-generic type.

On a 1,512-file Unity C# codebase (game code plus vendored UniTask, LeanTween and MsgPack), this branch alone changes the calls edges as follows:

  • 406 removed and 53 added;
  • self-loops go from 516 to 309.

I spot-checked samples of both sides against the source. The removed edges were mis-bindings such as transform.gameObject.SetActive(), float.Equals() and completionSource.TrySetResult() on the wrong class. The added edges were typed chains now reaching receiver_chain, such as t.Character.ApplyStatusFromHit() and client.Auth.SignInAnonymously().

How was this tested?

uv run pytest tests/test_csharp_member_chain_calls.py          # 15 passed
uv run pytest tests -k "csharp or cs_ or dotnet or razor or unity"   # 440 passed, 13 skipped
uv run pytest tests                                             # 7608 passed, 15 failed, 247 skipped
uv run ruff check graphify/extractors/engine.py tests/test_csharp_member_chain_calls.py   # clean
uv run pyright graphify/extractors/engine.py graphify/extract.py      # no new diagnostics

All 15 full-suite failures also fail on an untouched v8 checkout on the same machine (Windows 11, Python 3.14), so they come from the environment:

  • test_skillgen ×11;
  • test_hooks::test_shebang_parse_requires_leading_hash_bang;
  • the two *_memoization::test_absolute_path_lookup_skips_getcwd;
  • test_extract::test_c_include_out_of_root_target_id_is_deterministic_across_checkout_paths.

Graphify-specific checklist

  • I updated generated skill artifacts (uv run python -m tools.skillgen --bless) when changing their source fragments. (N/A: no fragments touched)
  • I confirmed that AST/structural extraction remains deterministic (no ambient state dependencies like ENV variables).
  • I reviewed changes for security implications (no unsafe interpolation into shell/Python).
  • I confirmed that no API keys or local-only graph data are included.
  • (If applicable) I disclosed AI authorship in my commit messages.

🤖 Generated with Claude Code

…ed method in the file

A C# member call whose receiver has no capturable name — a member chain
(`run.Sequence.Apply()`, `s.Items.Count()`), an invocation (`Make().Apply()`)
or a `new X(...)` — reached the per-file bare-name map, because the C# defer
rule required `member_receiver`. It then bound to the caller's own same-named
method as an EXTRACTED edge: a false self-loop (`a.look.LateUpdate()` inside
`LateUpdate()`), LINQ `Count()` bound to a local `Count()`, or a typed chain
landing on the wrong class instead of reaching `receiver_chain` resolution.

Every C# member call now defers. A typed chain still resolves through
`receiver_chain`; `new X(...).M()` (Graphify-Labs#1770) is typed from the construction so
it keeps its edge; anything untypable gets no edge (fail-closed).

Fixes Graphify-Labs#4418.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @nixvideojuego-ui. 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.

No issues found by static checks — no coupling regressions or blocking issues in the code graph. That is not the same as safe to merge: see what was not checked.

Not checked: tests were not run; formal verification proved 0 of 1 changed function(s) (1 not verified).

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

Not verified on this run: \_extract\_generic (unsupported).


Graphify review — findings

Stops C# member calls whose receiver has no capturable name (run.Sequence.Apply(), Make().Apply(), s.Items.Count()) from falling back to the file's bare-name map, which bound them to the caller's own same-named method as false self-loops or sibling edges. Every C# member call now defers: a typed chain still resolves through receiver_chain, and anything else gets no edge. new X(...).M() is typed from the constructed X, so those calls keep resolving under the stricter rule.

No blocking issues surfaced. 2 lower-confidence candidates did not survive cross-model review.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 920 functions depend on the 341 functions this change touches.

Health — grade A; 10 existing hotspot(s) in the area this change touches (pre-existing, not introduced here):

  • _extract_generic() — 20 callers, 40 callees (high)
  • extract_js() — 91 callers, 7 callees (high)
  • extract_objc() — 25 callers, 13 callees (high)
  • extract_xaml() — 19 callers, 17 callees (high)
  • extract_php() — 38 callers, 5 callees (high)
  • extract_cpp() — 37 callers, 5 callees (high)
  • extract_julia() — 22 callers, 8 callees (high)
  • extract_svelte() — 14 callers, 8 callees (high)
  • …and 2 more

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

Test selection

Test selection

37 of 412 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_member_chain_calls.py — impact, changed-test
  • tests/test_csharp_partial_classes.py — impact
  • tests/test_dotnet.py — impact
  • tests/test_ejs_extractor.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_java_member_calls.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_property_reads.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_given_instances.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.

Formal verification

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

@nixvideojuego-ui

Copy link
Copy Markdown
Contributor Author

Ran the full suite on Python 3.10 and 3.13 as suggested (Windows 11, uv sync --frozen, no optional extras), next to an untouched v8 checkout (e8eb76e) on the same machine:

Python this branch untouched v8
3.10.21 7610 passed, 17 failed, 243 skipped 7607 passed, 17 failed, 243 skipped
3.13.15 7609 passed, 17 failed, 244 skipped 7606 passed, 17 failed, 244 skipped

The extra passes are this PR's 3 new tests. The 17 failures are the same tests on the branch and on untouched v8, on both versions, so they come from the Windows environment:

  • test_skillgen ×11 and test_skillgen_input_path_injection ×3;
  • the two *_memoization::test_absolute_path_lookup_skips_getcwd;
  • test_extract::test_c_include_out_of_root_target_id_is_deterministic_across_checkout_paths.

On determinism: the change only reads the parsed tree and the per-class field tables already built during extraction. It does not depend on the environment, filesystem order or anything nondeterministic.

safishamsi added a commit that referenced this pull request Oct 13, 2026
C# nameless / `new X()` / `foreach` receiver resolution (#4422, #4428,
#4423) and `_`/case-distinct node ids (#4416) change AST extraction
output, so warm caches must re-extract.

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

Copy link
Copy Markdown
Member

Shipped in v0.9.90, just released to PyPI as graphifyy 0.9.90. Landed via an authorship-preserving cherry-pick (your commit keeps your name and counts on your contributor graph), which is why GitHub marks this closed rather than merged. Thanks @nixvideojuego-ui!

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 member call on a chained or invoked receiver binds to the caller's own same-named method

2 participants