Repository navigation
fix(csharp): new X() never binds to a method that shares X's name - #4428
nixvideojuego-ui wants to merge 1 commit into
Conversation
A C# object creation was resolved against every definition named X, methods included. Inside a helper like `static Bounds Bounds(..) => new Bounds(..)` (Unity's Bounds, outside the corpus) it became an EXTRACTED self-loop; across files the bare-name pass bound every `new List<T>()` in the corpus to an unrelated `List()` method, minting an INFERRED hub with one false caller per construction site. The same-file path now defers a construction whose bare-name target is a method, and the cross-file pass drops method candidates for `csharp_new` calls, next to the enum-member/property exclusion (Graphify-Labs#3815, Graphify-Labs#4245). A real type with the same name still wins. Dropping those candidates removes ties that used to hide a separate guess: a qualified construction (`new QuickSlotsBar.Slot()`) with several bare-name `Slot` classes went to the path-proximity tie-break, which ignores the qualifier and picks the Slot next to the caller. A qualified construction now takes the one candidate nested in a type named by the qualifier's last segment, or gets no edge; namespace qualifiers stay with `_resolve_csharp_qualified_calls`. Fixes Graphify-Labs#4419. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
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. |
There was a problem hiding this comment.
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 2 changed function(s) (2 not verified).
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: extract (vacuous: never exercised), \_extract\_generic (unsupported).
Graphify review — findings
Stops C# new X() from resolving to a method that happens to share X's name. In-file resolution now defers instead of self-looping inside static Bounds Bounds(..) => new Bounds(..), and the cross-file pass drops method candidates, so new List<T>() no longer collapses onto some List() method as an INFERRED hub. A qualified construction like new Outer.Slot() now binds only to the single Slot nested in a type named Outer instead of taking a path-proximity guess, and gets no edge when no such outer type exists.
No blocking issues surfaced. 3 lower-confidence candidates did not survive cross-model review.
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 3340 functions depend on the 665 functions this change touches.
Health — grade A; 10 existing hotspot(s) in the area this change touches (pre-existing, not introduced here):
extract()— 945 callers, 57 callees (high)_rebuild_code()— 177 callers, 59 callees (high)_extract_generic()— 20 callers, 40 callees (high)extract_js()— 91 callers, 7 callees (high)main()— 110 callers, 3 callees (high)extract_objc()— 25 callers, 13 callees (high)extract_xaml()— 19 callers, 17 callees (high)dispatch_command()— 2 callers, 132 callees (high)- …and 2 more
Verification — 3340 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: 3103 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
189 of 412 test file(s) selected (46%) via static blast radius.
tests/test_affected_overrides.py— impacttests/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_c_include_resolution.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_cpp_template_type_params.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— impacttests/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_chain_calls.py— impacttests/test_csharp_member_nodes.py— impacttests/test_csharp_object_creation.py— impact, changed-testtests/test_csharp_partial_classes.py— impacttests/test_csharp_tuple_type_refs.py— impacttests/test_csharp_type_resolution.py— impacttests/test_csharp_var_call_return_type.py— impacttests/test_csharp_verbatim_interpolation.py— impacttests/test_definition_file_portability.py— impacttests/test_detect.py— impacttests/test_dotnet.py— impacttests/test_duplicate_annotation_edges.py— impacttests/test_ejs_extractor.py— impacttests/test_elixir_defdelegate.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— impact- … and 139 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
|
Ran the full suite on Python 3.10 and 3.13 as suggested (Windows 11,
The extra passes are this PR's 5 new tests. The 17 failures are the same tests on the branch and on untouched
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. |
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]>
|
Shipped in v0.9.90, just released to PyPI as |
What does this PR do?
Fixes #4419.
A C#
new X(...)was resolved against every definition namedX, methods included:static Bounds Bounds(..) => new Bounds(..)(Unity'sBounds, outside the corpus) became anEXTRACTEDself-loop.new List<T>()to an unrelatedList()method, minting anINFERREDhub.Changes:
engine.py): a construction whose bare-name target is a method (tgt_nid in method_owner) is deferred to the cross-file pass.extract.py): forcsharp_newcalls, method candidates are dropped next to the existing enum-member and property exclusion (fix: prevent non-type nodes from hijacking C# type resolution #3815, C#: calls bind to enum members of the same name (follow-up to #3795) #4245). It reuses the lazily built_csharp_method_ownermap. A real type with the same name still wins.Slotclasses,new QuickSlotsBar.Slot()went todisambiguate_ambiguous_candidates, whose path proximity ignores the qualifier and picks theSlotnext to the caller. A qualified construction now skips that tie-break. It takes the single candidate nested (contains) in a type named by the qualifier's last segment, or gets no edge. Namespace qualifiers stay with_resolve_csharp_qualified_calls(C#:new Foo(...)produces no edge, so message publishers and locally built types look unused #2997).Type of change
Verification & Invariants
Invariants:
new X()constructs a type and never binds to a method.A qualified construction is resolved by its qualifier, never by path proximity over the bare name.
Read the CONTRIBUTING.md guide.
Reproduced the issue and identified the invariant.
Made the smallest fix necessary.
Added a regression test: 5 tests in
tests/test_csharp_object_creation.py. All 5 fail onv8(e8eb76e) and pass here.Kept the PR description synchronized with the final implementation.
Documented any limitations / unsupported cases explicitly.
Limitations:
On a 1,512-file Unity C# codebase, this branch alone changes the
callsedges as follows:Removed examples:
new WaitForSeconds()bound to UniTask'sWaitForSeconds()method (41 false callers);new Rect()bound to aRect()UI helper (23);new Stack<T>().Added examples:
new SkipUntil<T>(..)inside theSkipUntil()factory now reaching the class;new QuickSlotsBar.Slotreaching the rightSlot.The qualified constructions that were already right (
new FarmWaves.Entry(..)and similar) are kept.How was this tested?
Full suite: 7610 passed, 15 failed, 247 skipped. All 15 failures also fail on an untouched
v8checkout on the same machine (Windows 11, Python 3.14), so they come from the environment:test_skillgen×11,test_hooks×1, the two*_memoizationtests and onetest_extractcheckout-path test.Graphify-specific checklist
uv run python -m tools.skillgen --bless) when changing their source fragments. (N/A: no fragments touched)🤖 Generated with Claude Code