Skip to content

fix(csharp): make constructors nodes and link new/base/this to the overload by arity - #5054

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

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

Conversation

@rohit-jsfreaky

Copy link
Copy Markdown
Contributor

Closes #5053

What does this PR do?

C# constructors become nodes, and the calls that reach them are linked to the right overload:

  • new X(a, b) links to the X constructor with that arity. The existing edge to the type stays; this adds one.
  • : this(...) links to the own overload, and : base(...) to the base class constructor, also across files.
  • Calls inside a constructor body and inside its initializer arguments are credited to that constructor, not to the class.
  • A static constructor is its own node, and new never picks it. Primary constructors are nodes too, so they compete with explicit ones.

It fails closed: no constructor edge when two overloads take the same number of arguments, or when the base class is outside the corpus.

Node ids. A constructor gets _make_id(type_id, TypeName), the id a method named after the type would get. Other overloads are salted like method overloads. If a member like foo() in class Foo already owns that id, the constructor gets a salted id instead. On the three projects below, no existing node id changed or disappeared. All 1,423 new nodes are constructors.

AST cache schema 39 -> 40. #5052 and the accessor/operator PR also bump it to 40, so whichever lands second takes the next number.

Diff: extractors/engine.py +126 / -15, extract.py +136, extractors/csharp.py +15, interface_dispatch.py +3, an ARCHITECTURE.md note, 13 tests across 4 test files.

Behaviour change to flag

#4246 credited constructor-body calls to the class, because constructors had no node. Now they come from the constructor, so "what does class X call directly" shows fewer edges, and the constructor node shows them instead. I updated the two #4246 tests and one label list to match.

Earlier attempts

#3016 and #3247 (both open since August) add constructor_declaration to the method types, a 2-line change. On v8 that:

This PR handles each of those, and it adds the new / this(...) / base(...) links.

Numbers

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

kind Roslyn v8 this PR
ctor 710 474 497
static 948 830 897
same 2819 2586 2608
typed / inherited / interface / generic / other 986 / 422 / 188 / 321 / 84 838 / 376 / 104 / 264 / 71 850 / 381 / 106 / 265 / 73
total 7349 5544 (75.4%) 5678 (77.3%)
calls made inside a constructor 151 0 119
base(...) / this(...) initializers (separate Roslyn key) 130 0 80
wrong calls edges 264 266

No kind drops. Wrong edges change in four ways:

  • Removed (81): calls that were credited to the class.
  • Added but correct (73): initializer links that the Roslyn initializer key confirms. The main key has no initializers, so they count as "wrong" there.
  • Moved (6): existing wrong edges that now sit on the constructor.
  • Truly new (4): existing resolver limits now applied to constructor code, for example Add(content) picked by arity only.

46 of the 50 missed initializers are same-arity overloads, which fail closed by design.

Limitations

Type of change

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

Verification & Invariants

Invariants:

  • Existing node ids never change; new constructor ids are salted when taken.

  • A constructor edge is added only when exactly one overload fits the argument count.

  • 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_object_creation.py tests/test_csharp_underscore_collisions.py -q   # the 13 new tests fail on v8 source and pass here
uv run --frozen pytest tests -q                                  # 10208 passed, 0 failed (v8: 10198 passed, 0 failed)
uv run --frozen pytest tests/test_csharp*.py tests/test_dotnet*.py tests/*interface*.py -q   # 393 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       # the expected edges
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

…erload by arity

A C# constructor had no node. Calls in its body were credited to the
type (Graphify-Labs#4246), calls in `: base(...)`/`: this(...)` arguments were never
walked, and `new X(a, b)` could only point at the type, never at the
overload it runs. On Dapper, AutoMapper and Newtonsoft.Json (Roslyn answer
key) 151 call links made from constructors were all lost and none of the
130 constructor initializers was linked.

- Each constructor (instance, static, and a type's primary constructor)
  is a node owned by its type through a `method` edge, labeled
  `.TypeName()` with metadata kind "constructor" plus arity/signature.
  The id is `_make_id(type_id, TypeName)`, the one a method named after
  the type would get; other signatures are salted like method overloads
  (Graphify-Labs#4584), a static constructor is its own "static" signature, and if a
  member spelled like the type in another case (`foo()` in `Foo`)
  already owns that id the constructor takes a salted one. No existing
  node id changes (checked on all three projects).
- Body and initializer calls belong to the constructor.
- `new X(...)` sites and initializers are recorded in raw_calls with no
  callee (so every name-keyed consumer skips them and the id passes
  remap their caller). A tail C# pass links the constructor whose
  parameter count fits, next to the existing edge to the type.
  `: this(...)` uses the own type, `: base(...)` the single resolvable
  base. Two fitting overloads, an unresolved base, or a type the caller
  did not bind give no edge.
- Constructors are left out of every name-keyed call index (in-file
  label map, global label index, member-call index, overload index,
  interface dispatch), so a constructor can never be picked for an
  ordinary call or shadow its type.
- AST cache schema 40.

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

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

Not verified on this run: \_csharp\_overload\_index (unsupported), \_resolve\_csharp\_member\_calls (vacuous: never exercised), extract (vacuous: never exercised), \_csharp\_method\_signature (vacuous: never exercised), \_csharp\_pre\_scan\_name\_collisions (vacuous: never exercised), \_extract\_generic (unsupported), resolve\_interface\_dispatch (vacuous: never exercised).


Graphify review — findings

Adds C# constructors (instance, static and primary) as nodes owned by their type through a method edge, labeled .TypeName() with kind: "constructor". Each constructor reuses the id a method named after the type would get, with overloads, static constructors and case-only collisions (foo() in Foo) salted, so no existing id moves. new X(...) keeps its edge to the type and also links the constructor whose parameter count fits, as does : base(...)/: this(...), with _resolve_csharp_constructor_calls assigning each edge's confidence and score; two fitting overloads, an unresolved base or an unbound type fall back to the type edge alone. Bumps the AST cache schema to 40 so cached C# extractions without constructors 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 — 5427 functions depend on the 1036 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: extract() — 1153 callers, 69 callees
  • worse: _rebuild_code() — 261 callers, 73 callees
  • worse: walk() — 1 callers, 83 callees
  • worse: walk_calls() — 1 callers, 39 callees
  • new: _resolve_csharp_constructor_calls() — 0 callers, 6 callees

Verification — 5427 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: 4781 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 \_csharp\_overload\_index.

The verifier did not have enough to check \_csharp\_overload\_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: not verifiable: the input domain has 81 values but only 11 distinct were tested — a small finite domain must be EXHAUSTED, not sampled (an untested input could invert the result)

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\_method\_signature.

The verifier did not have enough to check \_csharp\_method\_signature, 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 121 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 \_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

Could not verify: Could not verify resolve\_interface\_dispatch.

The verifier did not have enough to check resolve\_interface\_dispatch, 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 12 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)

· 2 grounded finding(s) anchored inline below; 3 more finding(s) on lines outside this diff (see the check run).

Comment thread graphify/extract.py
e.pop("target_file", None)


def _resolve_csharp_constructor_calls(

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 — _resolve_csharp_constructor_calls()

fans out to 6 callees (efferent coupling).

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

add_edge(type_nid, ctor_nid, "method", line)
return ctor_nid

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 83 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 C# constructors as nodes with arity-correct new/base/this, @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#: constructors are not nodes, so new X(), this(...) and base(...) never reach the overload they call

2 participants