Skip to content

fix(vbnet): resolve calls through typed fields, Me.field and With blocks (#4588) - #4623

Open
Deepjyoti-Sarmah wants to merge 9 commits into
Graphify-Labs:v8from
Deepjyoti-Sarmah:fix/4588-vbnet-field-with-receivers
Open

Deepjyoti-Sarmah wants to merge 9 commits into
Graphify-Labs:v8from
Deepjyoti-Sarmah:fix/4588-vbnet-field-with-receivers

Conversation

@Deepjyoti-Sarmah

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #4588. Stacked on #4573, so only the last two commits are new: 467f15b (tests) and 25d072b (fix).

The VB resolver dropped calls made through a field, through Me.field, and inside With blocks:

Private _repo As Repository        ' F1-F5
_repo.Save()                       ' no edge
Me._repo.Save()                    ' no edge
With _repo
    .Load()                        ' no edge
End With

Fields had no declared type, so a field receiver hid the call and nothing replaced it.

 resolve(call)
   locals / parameters
+  field of the caller's type (all partial files), then VB bases nearest first
+    declared type known and unique -> member of that type, INFERRED 0.85
+    untyped / external / ambiguous -> no edge (still hides a same-named type)
   type or Module named by the receiver

 walk(method body)
+  With target stack: `.M()` -> call on the innermost target
+    name / Me.name -> resolved like name.M()
+    New T()        -> typed receiver T
+    anything else  -> no edge
  • Only As T and As New T() give a field a type. Private x = New T() is Object to the compiler, because Option Infer doesn't apply to fields.
  • The field's type is resolved with the declaring file's namespace and imports.
  • Me.f, MyClass.f and OwnType.f resolve like f.
  • A typed local or field of an interface type binds to the interface member, as the compiler does.
  • VB→C# edges keep the _vbnet_resolved marker from fix(vbnet): resolve cross-file calls to Module members, typed locals and C# statics (#4570) #4573.
  • watch.py forwards declared_type and imports. _AST_CACHE_SCHEMA 21 → 22.

Type of change

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

Verification & Invariants

Invariant: a VB calls edge points only at the method the compiler would bind. When the receiver's type isn't known for sure, there's no edge, never a guess.

I checked each case against the VB compiler (dotnet SDK 8.0, 30 cases). A local, a parameter or a Shadows field hides a field. A field hides a type of the same name. Nested With uses the innermost target. Lambdas see the With target. An untyped field is Object (BC30209 under Strict On).

Persisted state: field and property nodes gain metadata.owner, declared_type, namespace and imports. The schema bump re-extracts cached VB files. The change is two-way: reverting it and bumping the schema again restores the old graph.

Known gap: a call whose receiver is a field declared in another partial file or a base class can still bind to a type with the same name in the calling file (same-file shortcut). #4573 behaves the same way, and it takes a field named exactly like a type.

  • 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?

# before the fix (tests only, 467f15ba)
pytest tests/test_vbnet_extractor.py      -> 29 failed, 58 passed, 2 xfailed

# after (25d072bc)
pytest tests/test_vbnet_extractor.py      -> 87 passed, 2 xfailed (existing P5/P6)
pytest (full suite, PYTHONPATH=checkout)  -> 8550 passed, 14 skipped, 2 xfailed, 0 failed
ruff check graphify/extractors/vbnet.py graphify/watch.py graphify/cache.py tests/test_vbnet_extractor.py -> clean

# reporter's repro, GRAPHIFY_BACKEND=none
F1-F5, W1-W4, P1 -> 10/10 edges found (F4/W4 reach C# .Total())

# compiler ground truth
podman run mcr.microsoft.com/dotnet/sdk:8.0 (vbc, 30 cases)

Graphify-specific checklist

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

@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @Deepjyoti-Sarmah. 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 Oct 21, 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 3 changed function(s) (1 sampled, not proven, 2 not verified).

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

Not verified on this run: build\_from\_json (vacuous: never exercised), \_rebuild\_code (unsupported).


Graphify review — findings

Adds cross-file resolution of VB.NET calls: a receiver's declared type, the caller's namespace and imports, and a module's members now bind a call to a single target, including C# ones, through the new resolve_vbnet_calls in place of resolve_vbnet_partial_calls on the .vb resolver hook. In build_from_json, an INFERRED calls edge the VB resolver bound to one C# target (_vbnet_resolved) is no longer dropped by the cross-language filter, while a C# bare name matched to a VB Module member is still dropped. Bumps _AST_CACHE_SCHEMA to 22 so cached VB extractions re-run, since they now carry receiver, type, owner, namespace and import data.

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 — 5011 functions depend on the 735 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: extract() — 989 callers, 59 callees
  • worse: _rebuild_code() — 190 callers, 60 callees
  • worse: build_from_json() — 269 callers, 22 callees
  • worse: save_cached() — 50 callers, 9 callees
  • worse: process_type() — 1 callers, 7 callees

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

Test selection

Test selection

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

Escalated to a full run for safety — 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_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_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 — impact, full-run-safety
  • tests/test_atomic_version_stamp.py — full-run-safety
  • tests/test_atomic_writes.py — impact, 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 — impact, full-run-safety
  • tests/test_benchmark.py — impact, full-run-safety
  • tests/test_benchmark_raw_graph.py — impact, full-run-safety
  • tests/test_benchmark_real_query.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_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_stale_import_target.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_sensitive_resolution.py — impact, full-run-safety
  • tests/test_charmap_encoding.py — impact, full-run-safety
  • tests/test_chunking.py — impact, full-run-safety
  • tests/test_cjs_module_extension.py — impact, full-run-safety
  • tests/test_claude_cli_backend.py — impact, full-run-safety
  • tests/test_claude_md.py — full-run-safety
  • tests/test_cli_broken_pipe.py — full-run-safety
  • tests/test_cli_export.py — impact, full-run-safety
  • tests/test_cli_help.py — full-run-safety
  • tests/test_cloud_cta.py — full-run-safety
  • tests/test_cluster.py — impact, full-run-safety
  • tests/test_cluster_ambiguous_scale.py — full-run-safety
  • tests/test_cluster_exclude_hubs.py — full-run-safety
  • … and 386 more

changed code file(s) with no mapped test (graphify/extractors/vbnet.py) — 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.

Docs that may be stale (advisory)

…and 10 more.

Formal verification

Could not verify: Could not verify build\_from\_json.

The verifier did not have enough to check build\_from\_json, 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 11 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous

No difference found (not proven): No behavior difference found in extract\_vbnet (not a proof).

The verifier ran both versions of extract\_vbnet on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

Could not verify: Could not verify \_rebuild\_code.

The verifier did not have enough to check \_rebuild\_code, 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: nondeterministic output (both versions disagreed with themselves on the witness) — not a behaviour change; a function whose output is not a function of its inputs (random / time / uuid / os.urandom, or state carried across calls) cannot be soundly distinguished by execution, so this tier abstains for the whole function

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

details.update(declared_type=declared, namespace=namespace, imports=list(file_imports))
return details

def process_type(block: Node, parent_id: str, namespace: str) -> 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 — process_type()

fans out to 7 callees (efferent coupling).

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

@TerraVenil

Copy link
Copy Markdown

I tested bc386bf7d9 on a large mixed VB.NET/C# WinForms codebase. Calls through fields and With blocks now resolve, and VB → C# edges went from 1,131 (0fcda3a129) to 1,461. In my sample of real call sites, the only one still missing is a VB call to an overloaded C# method:

// NsRules.cs
namespace Acme.Rules
{
    public static class NsRules
    {
        public static string Banner(int x) { return ""; }
        public static string Banner(int x, string format) { return format; }
    }
}
' Caller.vb
Imports Acme.Rules

Public Class Caller
    Public Sub L_OverloadOneArg()
        NsRules.Banner(1)
    End Sub
End Class
GRAPHIFY_BACKEND=none graphify extract l-repro --code-only

Expected: L_OverloadOneArg --calls--> Banner(int). Actual: the graph has no calls edge at all; the two Banner nodes are there with metadata.arity 1 and 2.

lookup_member leaves C# targets unresolved when there is more than one (vbnet.py:288-289, "a C# target has no arity here"). Since #4591, the C# nodes do carry it, and _csharp_pick_overload (extractors/engine.py) already chooses an overload from an argument count, including min_arity and variadic. Could the C# branch of lookup_member pass the C# nodes and the VB call's arity to it, and fall back to "no edge" when it returns None? Two overloads with the same arity (M(int) / M(string)) would still have no edge, which matches what C#-to-C# calls get today.

@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 review View in Graphify

Review before merging · Merge confidence 3/5

2 bugs · 7 possible issues to check · High impact

VB.NET extraction now resolves more calls through typed locals, fields, and With blocks.

P2  A lambda’s local can redirect calls outside the lambda · vbnet.py:927

P2  Lambda parameters can resolve calls through a shadowed field · vbnet.py:880

7 possible issues we couldn't confirm

They don't change the score.

What this review covered
  • Some lookups asked for files or lines that do not exist; the review was told and carried on.
  • One review pass used all of its turns for reading code, so it reported from what it had already read.
  • 6 of 6 changed files inspected. This is scope, not a correctness guarantee.
Code graph · 6708 functions depend on this change
  • 6 functions became more coupled. Largest: extract() (1350 callers), build_from_json() (339 callers), save_cached() (63 callers).
  • 459 of 620 test files are affected by this change.
  • Gate, test list and every flagged function: in the Graphify check.

Reviewed d371f36 · 2 earlier findings not re-checked

…and C# statics (Graphify-Labs#4570)

VB.NET calls produced a `calls` edge only when caller and callee were in
the same file. A call to a Module Sub declared elsewhere, a qualified
call such as `Helpers.LogIt(...)`, a call through a local declared with
`As New T()`, and a call to a C# static method were all dropped by the
extractor, and the shared name pass skips member calls, so nothing
picked them up.

The extractor now keeps every call it cannot resolve in its own file as
a raw call, with the receiver, the receiver's kind (none, Me, MyBase, a
local, or a name), the declared type of a local, parameter or loop
variable, the caller's namespace and Imports, and the nested types of
the caller's type. A new resolver, resolve_vbnet_calls, binds them with
VB's own scoping rules, taken from compiling each case with the .NET 8
SDK:

- the caller's type and its base classes hide a Module's member of the
  same name, whatever its arity;
- a field, a property or an event of that name also hides the Module's
  Sub (a delegate field is invoked instead);
- a Module is in scope only through its own, an enclosing, or an
  imported namespace, and two in-scope Modules that declare the name
  give no edge;
- a field, a property or a nested type named like the receiver hides
  the type;
- a type name must be unique in scope;
- a C# target needs to be the only method of that name on its type,
  because C# method nodes carry no arity.

Only a unique match makes an edge. Qualified and unqualified Module
calls and base-class calls are EXTRACTED; calls through a typed local
and casefolded C# names are INFERRED (0.85). When the caller's base
chain leaves the corpus (a Form, a Page), the edge is INFERRED with
context `external_base_may_hide`, since that base may declare the name.
The resolver replaces resolve_vbnet_partial_calls, which stays as an
alias and keeps its registry name, and its `partial_type_call` edges
are unchanged.

v8 bound two kinds of call to a same-named method of the caller's own
type, which the compiler does not: `.Save()` inside a With block (it
calls the With object's method) and a call of a local delegate (the
local hides the method). Both wrong edges are gone.

watch.py now forwards the metadata keys `owner`, `full_name`,
`accepted_arities` and `namespace` to the resolvers as context for an
incremental rebuild. Two side effects follow. The partial-class
resolver, which needs `owner` and `accepted_arities`, now works across
changed and unchanged files. And the C# resolvers see the namespace of
unchanged types: a `using Beta` caller of a `Svc` declared in both
Alpha and Beta bound to Alpha.Svc on an incremental rebuild and to
Beta.Svc on a full one, and now binds to Beta.Svc on both.

The AST cache schema goes from 17 to 18 because VB raw calls change.

Limits: project-level Imports and RootNamespace from the .vbproj are not
read; in a multi-project corpus whose projects do not reference each
other, a Module from an unreferenced project can be bound; Shared
versus instance is not modeled; a call through a field and a call
inside a With block are not resolved to the receiver's type.
…y-Labs#4570)

build.py's cross-language phantom filter drops an INFERRED call whose
endpoints are in different families, and .vb has none there, so every
INFERRED VB -> C# edge the VB resolver made was dropped: a call from a
class whose base leaves the corpus (a Form) and a call through a typed
local. The resolver's edges now carry _vbnet_resolved, and the filter
keeps them. A C# bare name matched to a VB Module member by the shared
name pass is still dropped: C# cannot reach it without the Module name.
…cks (Graphify-Labs#4588)

Fields and properties carry their declared type (As T / As New T()), owner,
namespace and imports. The resolver looks a receiver up as a field of the
caller's type, then its VB bases nearest first, and binds to the declared
type's member as INFERRED. With blocks track the innermost target. watch.py
forwards the new metadata; AST cache schema 21 -> 22.
@Deepjyoti-Sarmah
Deepjyoti-Sarmah force-pushed the fix/4588-vbnet-field-with-receivers branch from da08d73 to d371f36 Compare November 24, 2026 13:48
Comment on lines +926 to +927
for body, caller_id, owner_key, type_name, namespace, nested_types in bodies:
locals_table = method_locals(body)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2  A lambda’s local can redirect calls outside the lambda

A local declared inside a lambda can make a later call in the enclosing method resolve to the wrong type, or disappear from the graph.

Exclude lambda-local declarations from method_locals.

Evidence · checked against the code

Expected: The outside call is resolved using the enclosing field’s type, or remains unresolved if that type cannot be determined.
Actually: The lambda declaration enters the method-wide locals table, so the outside call may use the lambda-local type or be left unresolved.

  • Independent source review: Checked the resolver’s field lookup path: it can use an enclosing field’s declared type when the call is classified as a field/name receiver, but a matching name in the locals table is classified as a local first. That field path does not mitigate the reported case. The inspected VB tests cover other call-resolution behavior but not lambda-local shadowing.
  • Some lookups asked for files or lines that do not exist; the review was told and carried on.
  • The added tests exercise calls inside lambdas in With blocks, but do not test a lambda-local name colliding with a field used outside the lambda.
Prompt to fix with AI
In graphify/extractors/vbnet.py, method_locals (lines 926-927):
Problem: A lambda’s local can redirect calls outside the lambda
Expected: The outside call is resolved using the enclosing field’s type, or remains unresolved if that type cannot be determined.
Actually: The lambda declaration enters the method-wide locals table, so the outside call may use the lambda-local type or be left unresolved.
Fix it at the cause, and add a test that fails without the fix.

Graphify · Checked against the code · View in Graphify

Comment on lines +879 to +880
parameters = body.child_by_field_name("parameters")
for parameter in (parameters.named_children if parameters is not None else []):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2  Lambda parameters can resolve calls through a shadowed field

A call inside a lambda can be linked to the enclosing class’s field type even when a lambda parameter with the same name shadows that field.

Add lambda parameters to the local-name table while resolving their bodies.

Evidence · checked against the code

Expected: The call should resolve using the lambda parameter's type, or remain unresolved if that type cannot be resolved.
Actually: The lambda parameter is omitted from the method-local name table, so the resolver can use the shadowed field or property's declared type and link to the wrong method.

  • Independent source review: Checked the receiver classification and resolver path: the parameter is absent from locals_table, and the name-receiver path uses find_field(owner, first) before resolving against the field's declared type. The enclosing-field lookup does not account for lambda-parameter shadowing. The inspected VB.NET tests do not cover this case.
  • Some lookups asked for files or lines that do not exist; the review was told and carried on.
Prompt to fix with AI
In graphify/extractors/vbnet.py, method_locals (lines 879-880):
Problem: Lambda parameters can resolve calls through a shadowed field
Expected: The call should resolve using the lambda parameter's type, or remain unresolved if that type cannot be resolved.
Actually: The lambda parameter is omitted from the method-local name table, so the resolver can use the shadowed field or property's declared type and link to the wrong method.
Fix it at the cause, and add a test that fails without the fix.

Graphify · Checked against the code · View in Graphify

This branch has not been deployed

No deployments
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]: vbnet: no calls edge through field receivers or With blocks (WinForms-style forms)

2 participants