Skip to content

fix(csharp): credit calls in accessors, indexers and operators to that member - #5056

Closed
rohit-jsfreaky wants to merge 1 commit into
Graphify-Labs:v8from
rohit-jsfreaky:fix/csharp-members
Closed

rohit-jsfreaky wants to merge 1 commit into
Graphify-Labs:v8from
rohit-jsfreaky:fix/csharp-members

Conversation

@rohit-jsfreaky

Copy link
Copy Markdown
Contributor

Closes #5055

What does this PR do?

Calls made inside C# getters, setters, indexers and operators are now credited to that member:

  • Getters and setters: property accessor bodies are walked for calls, including expression-bodied properties (int Sum => base.Twice();). The calls are credited to the property node.
  • Indexers: an indexer becomes a node with id _make_id(type, "this"), salted per signature. Explicit-interface indexers (IFoo.this[...]) are kept apart.
  • Operators: each operator and conversion operator becomes a node with id _make_id(type, "operator", <signature hash>).

Calls inside these bodies resolve the same way as calls inside methods: own type first, typed receivers across files, base. calls, and partial types split across files.

An accessor body is walked only when its own declaration created the node. Without that guard, an explicit-interface property IRun.Next shared the id of a method Next(), and its calls turned into a self-loop on the method. There is a test for it.

On the three projects below, no existing node id changed or disappeared. All 151 new nodes are indexers or operators. AST cache schema 39 -> 40. #5052 and #5054 also bump it to 40, so whichever lands second takes the next number.

Diff: extractors/engine.py +113 / -6, extract.py +19 / -1, an ARCHITECTURE.md note, 9 tests in the new tests/test_csharp_member_nodes.py.

Numbers

Newtonsoft.Json, Dapper and AutoMapper, compared with Roslyn (same harness as #5003):

kind Roslyn v8 this PR
same 2819 2586 2737
ctor 710 474 525
static 948 830 860
generic 321 264 269
typed / inherited / interface / other 986 / 422 / 188 / 84 838 / 376 / 104 / 71 840 / 377 / 104 / 71
total 7349 5544 (75.4%) 5784 (78.7%)
calls made inside a getter or setter 144 0 92
calls made inside a conversion operator 186 0 148
wrong calls edges 264 270

No kind drops. Of the 6 new "wrong" edges:

  • Correct after all (4): links to Dapper's [GeneratedRegex] partial methods. The harness calls them external only because their bodies are source-generated.
  • Truly wrong (3): GetType() binds to Newtonsoft's own JToken.GetType instead of object.GetType(), the same mistake v8 already makes inside methods.

Not in this PR

  • Calls to properties (obj.Name, obj.Name = x): Roslyn finds 3,488 of these on these projects, about half of them on auto-properties. That is data access rather than calls. It needs member-access typing and a choice of relation, so it belongs in its own PR. (feat(csharp): link a property/field read to the member it reads #3120 tried reads only. It records writes as reads, and it no longer applies to v8.)
  • An explicit-interface property whose id a method already owns: its calls are dropped, so they fail closed.

Type of change

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

Verification & Invariants

Invariants:

  • Existing node ids never change.

  • A member's body is walked only when that member's own declaration created the node, so calls are never credited to a different member that shares the id.

  • Read the CONTRIBUTING.md guide.

  • Reproduced the issue and identified the invariant.

  • Made the smallest fix necessary.

  • Added a regression test (if bug fix) or isolated boundary test.

  • Kept the PR description synchronized with the final implementation.

  • Documented any limitations / unsupported cases explicitly.

How was this tested?

uv run --frozen pytest tests/test_csharp_member_nodes.py -q     # 9 passed; 8 fail on v8 source (the IRun.Next test guards the self-loop above)
uv run --frozen pytest tests -q                                  # 10207 passed, 0 failed (v8: 10198 passed, 0 failed)
uv run --frozen pytest tests/test_csharp*.py tests/test_dotnet*.py tests/*interface*.py -q   # 392 passed on Windows
uv run --frozen ruff check .                                     # clean
uv run --frozen pyright <changed files>                          # same errors as v8, none new
graphify update . on the issue's repro, v8 and this branch       # v8: no edges; here: all 5 expected
Roslyn harness on Newtonsoft.Json, Dapper, AutoMapper            # numbers above, 0 existing ids changed

Graphify-specific checklist

  • I updated generated skill artifacts (uv run python -m tools.skillgen --bless) when changing their source fragments. (Not needed: no skill fragments changed.)
  • 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 no API keys or local-only graph data are included.
  • (If applicable) I disclosed AI authorship in my commit messages.

🤖 Generated with Claude Code

…t member

A C# property's accessor bodies, an indexer and a user-defined operator
or conversion were never walked, so every call made inside them was lost.
On Dapper, AutoMapper and Newtonsoft.Json (Roslyn answer key) that is 144
call links made from property/indexer accessors and 186 from conversion
operators, none found.

- A property's `get`/`set` bodies and an expression body (`int P =>
  F();`) are walked with the existing property node as the caller. An
  auto-accessor has no body and an initializer runs in the constructor,
  so neither adds calls. Only the declaration that owns the property
  node is walked: when the id is already another member's (an explicit
  `IFoo.Name` property spelled like a method `Name()`), its calls are
  dropped instead of being credited to that member.
- An indexer is a `this[]` node beside the properties (`defines`,
  context `field`), id `_make_id(type_id, "this")`, salted per
  signature (including an explicit interface) and away from a member
  spelled `This`.
- An operator or conversion is a `.operator +()` / `.operator int()`
  node owned through `method`; its id always carries a hash of the
  signature, since several conversions share one parameter list.
- A property/indexer counts as owned by its type for caller lookups
  (in-file unqualified calls, `this.`/`base.` member calls, the
  partial-type own-type preference), like a method. It is never a call
  target by name, and `operator` is kept out of the member-call index.
- No existing node id moves (checked on all three projects).
- AST cache schema 40.

Calls TO properties, indexers and operators are not linked: in these
projects they are about 3,500 property get/set links (more than half
to auto-properties), 27 indexer and 60 conversion links, against 0
user-defined binary operator calls. Linking them needs member-access
typing and a decision on the relation, so it is left out.

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

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

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

@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Nov 6, 2026

@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 4 changed function(s) (4 not verified).

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

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


Graphify review — findings

Adds C# property and indexer accessor bodies (including expression bodies) to the call walk, with the member as the caller and owned by its type for unqualified, this./base. and partial-type lookups, like a method. Indexers become this[] nodes with a signature-salted id kept distinct from a member spelled This, and user-defined operators and conversions become .operator +() / .operator int() nodes whose ids hash the signature, since several conversions share one parameter list. These members are never call targets by name, existing ids don't move, and the AST cache schema goes to 40, so cached extractions re-run.

Review partial — this diff was larger than one review pass covers, so later files were not reviewed; some findings may be missing.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 5207 functions depend on the 899 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: walk() — 1 callers, 82 callees

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

Test selection

Test selection

526 of 526 test file(s) selected (100%) via static blast radius.

Escalated to a full run for safety (noncode-change, uncovered-code) — the selection is not trustworthy on its own (see below). CI should run the whole suite.

  • tests/pi.test.ts — full-run-safety
  • tests/test_4874_jvm_resolution.py — impact, full-run-safety
  • tests/test_4909_reference_binding_scale.py — full-run-safety
  • tests/test_4978_reconcile_cost.py — impact, full-run-safety
  • tests/test_4992_ts_import_types.py — impact, full-run-safety
  • tests/test_affected_cli.py — full-run-safety
  • tests/test_affected_defines.py — full-run-safety
  • tests/test_affected_member_seed.py — full-run-safety
  • tests/test_affected_overrides.py — impact, full-run-safety
  • tests/test_affected_path_file_node.py — full-run-safety
  • tests/test_affected_seed_reference_forms.py — full-run-safety
  • tests/test_agents_platform.py — full-run-safety
  • tests/test_alias_folding.py — impact, full-run-safety
  • tests/test_analyze.py — impact, full-run-safety
  • tests/test_anthropic_custom_endpoint.py — full-run-safety
  • tests/test_antigravity_install.py — full-run-safety
  • tests/test_apm_fallback_version.py — full-run-safety
  • tests/test_architecture_doc.py — full-run-safety
  • tests/test_astro_extraction.py — impact, full-run-safety
  • tests/test_astro_import_ids.py — impact, full-run-safety
  • tests/test_atomic_canvas_export.py — full-run-safety
  • tests/test_atomic_version_stamp.py — full-run-safety
  • tests/test_atomic_writes.py — full-run-safety
  • tests/test_backend_env_isolation.py — full-run-safety
  • tests/test_backend_extras.py — full-run-safety
  • tests/test_backend_opt_in.py — full-run-safety
  • tests/test_benchmark.py — full-run-safety
  • tests/test_benchmark_raw_graph.py — full-run-safety
  • tests/test_benchmark_real_query.py — full-run-safety
  • tests/test_binary_media_words.py — impact, full-run-safety
  • tests/test_blade_extractor.py — impact, full-run-safety
  • tests/test_build.py — impact, full-run-safety
  • tests/test_build_located_semantic_identity.py — impact, full-run-safety
  • tests/test_build_merge_dedup_scope.py — impact, full-run-safety
  • tests/test_build_merge_ghost_fold_4955.py — impact, full-run-safety
  • tests/test_build_merge_hyperedges_and_prune.py — impact, full-run-safety
  • tests/test_build_merge_shrink_guard.py — impact, full-run-safety
  • tests/test_builtin_global_type_refs.py — impact, full-run-safety
  • tests/test_c_include_resolution.py — impact, full-run-safety
  • tests/test_cache.py — impact, full-run-safety
  • tests/test_cache_long_paths.py — impact, full-run-safety
  • tests/test_cache_stale_import_target.py — impact, full-run-safety
  • tests/test_cache_windows_case_4925.py — impact, full-run-safety
  • tests/test_callflow_html.py — full-run-safety
  • tests/test_cargo_introspect.py — full-run-safety
  • tests/test_cargo_missing_manifest.py — full-run-safety
  • tests/test_carried_hyperedge_remap.py — impact, full-run-safety
  • tests/test_case_only_decl_ids_4904.py — impact, full-run-safety
  • tests/test_case_sensitive_resolution.py — impact, full-run-safety
  • tests/test_charmap_encoding.py — impact, full-run-safety
  • … and 476 more

non-code file(s) changed (ARCHITECTURE.md) → running the full suite for safety (a code graph can't see config/fixture/data deps)

changed code file(s) with no mapped test (ARCHITECTURE.md) — a coverage gap or a missing link — running the full suite rather than only the selected tests

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.

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 \_csharp\_pre\_scan\_name\_collisions.

The verifier did not have enough to check \_csharp\_pre\_scan\_name\_collisions, 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 253 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly AttributeError — 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

· 1 grounded finding(s) anchored inline below.

csharp_method_scopes[id(body)] = (decl, class_nid)
function_bodies.append((member_nid, body))

def walk(node, parent_class_nid: str | None = None) -> None:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Health regression — walk()

fans out to 82 callees (efferent coupling).

Grounded coupling-delta finding (deterministic), not an LLM guess.

safishamsi added a commit that referenced this pull request Nov 8, 2026
#5058, #5060, #5062, #5054 and #5056 each change per-file Solidity or C#
extraction output and each bumped _AST_CACHE_SCHEMA to 40 on their own. Landed
together in one release window they share a single bump; this folds their
descriptions into one chained schema-40 comment over the prior 39 so a warm
cache re-runs the affected Solidity and C# extractions exactly once.

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

Copy link
Copy Markdown
Member

Landed on v8 and shipped in 0.9.104 (now on PyPI). I cherry-picked your commit with -x so it keeps your authorship. Thanks for crediting C# accessor/indexer/operator calls to the member, @rohit-jsfreaky.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: C#: calls inside getters, setters, indexers and operators produce no edge

2 participants