Skip to content

fix(vbnet): count ByVal Optional parameters as optional (#5320) - #5327

Closed
Deepjyoti-Sarmah wants to merge 2 commits into
Graphify-Labs:v8from
Deepjyoti-Sarmah:fix/5320-vbnet-optional-modifier-order
Closed

Deepjyoti-Sarmah wants to merge 2 commits into
Graphify-Labs:v8from
Deepjyoti-Sarmah:fix/5320-vbnet-optional-modifier-order

Conversation

@Deepjyoti-Sarmah

Copy link
Copy Markdown
Contributor

What does this PR do?

Refs #5320 (point 2, ByVal Optional). A VB.NET parameter written ByVal Optional x As Integer = 0 is counted as required, so a call that leaves the argument out gets no calls edge.

The extractor decides whether a parameter is optional by whether its text starts with optional . VB allows the modifiers in either order, and ByVal Optional x starts with ByVal:

 Sub B(ByVal Optional x As Integer = 0)
-  accepted_arities [1]      -> B() matches nothing, no edge
+  accepted_arities [0, 1]   -> B() binds to B
-required_arity = sum(not text.startswith("optional ") for parameter in parameters)
+required_arity = sum(parameter.child_by_field_name("default_value") is None for parameter in parameters)

In VB a parameter has a default value exactly when it is Optional. I checked this with the .NET 8 SDK compiler:

Sub B(ByVal Optional x As Integer = 0)  B()   -> compiles, prints "B 0"
Sub B(ByRef Optional x As Integer = 0)  B()   -> compiles
Sub B(ByVal x As Integer = 0)                 -> BC32024: Default values cannot be supplied for parameters that are not declared 'Optional'.
Sub B(Optional ByVal x As Integer)            -> BC30812: Optional parameters must specify a default value.

tree-sitter-vb-dotnet 0.3.0 puts an ERROR node inside ByVal Optional x, but it still keeps the default_value field on the parameter, so the check no longer depends on modifier order or on how the grammar recovers.

The rest of #5320

  • Point 1 (qualified and Module calls to another file) is fix(vbnet): resolve cross-file calls to Module members, typed locals and C# statics (#4570) #4573. I rebased it onto 0.9.112 today; on that branch the issue's DataLayer.LoadCustomers() and HelperFunction() cases both get an edge.
  • Multi-line string literals did not reproduce. With the issue's snippet and with a multi-line JS body containing ' and {}, the ERROR node stays inside the one statement and every method and call in the file survives. I asked on the issue for a file that loses its methods.
  • Every method in the file lost did not reproduce for ByVal Optional either. The methods survive; only calls that leave out the optional argument were dropped, which is what this PR fixes.
  • --force served old AST results is expected for a local patch. --force skips the semantic cache, and the AST cache is keyed on the package version, so a released version does not hit this.

Type of change

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

Verification & Invariants

Invariant: a VB.NET method's accepted_arities runs from its required parameter count to its total, where a parameter is required exactly when it has no default value.

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

Merge Danger

Door: two-way. One expression in graphify/extractors/vbnet.py plus the cache schema bump. Reverting the fix commit restores 0.9.112.

Blast Radius: small. VB.NET only. Methods whose optional parameters were written ByVal Optional or ByRef Optional gain the lower arities, so calls that leave those arguments out now resolve. Any other parameter gets the same arity as before. _AST_CACHE_SCHEMA goes from 48 to 49 so cached VB results from before the fix are re-extracted. #4573 also bumps the schema, so whichever of the two lands second needs a one-line rebase.

Limitations

  • ParamArray parameters still count as one required argument. That is a separate gap.
  • A parameter whose name the grammar loses (it reads Optional as the name in ByVal Optional x) keeps that wrong name. Only the arity is used for call binding, and that is now correct.

How was this tested?

The issue's second snippet, with a call each way:

Module M
    Sub B(ByVal Optional x As Integer = 0)
        Other()
    End Sub
    Sub Other()
        B()
    End Sub
End Module

before  calls: B -> Other
after   calls: B -> Other, Other -> B

New tests in tests/test_vbnet_extractor.py:

test_vbnet_optional_parameter_accepts_the_omitted_argument_in_any_modifier_order
  [Optional ByVal | ByVal Optional | Optional ByRef | ByRef Optional | Optional]
  accepted_arities == [0, 1] and Caller -> B
test_vbnet_required_parameters_after_byval_stay_required
  Sub B(ByVal x)                                -> [1], B() makes no edge
  Sub F(a As Integer, ByVal Optional b = 1)     -> [1, 2]
VB tests
0.9.112 340268a7 (test commit only) 3 failed, 15 passed (ByVal Optional, ByRef Optional, the mixed F)
this branch 18 passed

Full suite, run on this branch and on 0.9.112 340268a7 in the same venv:

failed passed
0.9.112 76 11515
this branch 76 11521

The 76 failures are the same tests on both trees. Most are CLI tests that shell out to python -m graphify, which in my venv resolves to an editable install of a different checkout (error: unknown command 'section'). The other 6 passes on this branch are the new tests.

ruff check graphify/extractors/vbnet.py tests/test_vbnet_extractor.py  -> All checks passed

Graphify-specific checklist

  • I updated generated skill artifacts (uv run python -m tools.skillgen --bless) when changing their source fragments. (N/A: no skill change.)
  • 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). (N/A: reads a parse-tree field.)
  • I confirmed no API keys or local-only graph data are included.
  • (If applicable) I disclosed AI authorship in my commit messages. (No trailer in the commit messages.)

@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Nov 18, 2026
@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.11 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 code review View in Graphify

Review completed · 3517ddb86e21

Tip

Merge confidence: 5/5 · Looks safe to merge · 🟠 High impact
No issues reported

VB.NET callable arity now treats parameters with default values as omittable, regardless of modifier order.

Full summary

VB.NET callable arity now treats parameters with default values as omittable, regardless of modifier order. The cache schema is bumped so cached extractions are refreshed.

Code graph and static checks · 3712 functions depend on this change

Impact & health

Impact — 3712 functions depend on the 129 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: extract() — 1284 callers, 78 callees

Formal checks — 3712 functions this change can affect weren't formally checked in this review. Formal checks are informational only.

Gate & verification

✅ PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 2163 function(s) in the blast radius were not formally verified this run

Test selection

58 of 593 test file(s) selected (10%) via static blast radius.

ℹ️ 1 changed file rests on a single covering test (graphify/extractors/vbnet.py). The selection is only as good as that one test — raise minCoveringTests to run the full suite instead when coverage is this thin.

  • tests/test_binary_media_words.py — impact
  • tests/test_cache.py — impact
  • tests/test_cache_long_paths.py — impact
  • tests/test_cache_stale_import_target.py — impact
  • tests/test_cache_windows_case_4925.py — impact
  • tests/test_charmap_encoding.py — impact
  • tests/test_chunking.py — impact
  • tests/test_code_only_scope_4923.py — impact
  • tests/test_cpp_template_members.py — impact
  • tests/test_csharp_partial_classes.py — impact
  • tests/test_definition_file_portability.py — impact
  • tests/test_detect.py — impact
  • tests/test_extract.py — impact
  • tests/test_extract_cache_location.py — impact
  • tests/test_extract_cli.py — impact
  • tests/test_grammar_cache_key.py — impact
  • tests/test_hook_content_freshness.py — impact
  • tests/test_ignore_file_encoding.py — impact
  • tests/test_incremental_mtime_collision.py — impact
  • tests/test_java_member_calls.py — impact
  • tests/test_java_nested_type_identity.py — impact
  • tests/test_js_member_collisions.py — impact
  • tests/test_language_override_lifecycle.py — impact
  • tests/test_language_overrides.py — impact
  • tests/test_linked_worktree_reconcile.py — impact
  • tests/test_llm_ambiguous_fragments.py — impact
  • tests/test_llm_backends.py — impact
  • tests/test_manifest_ingest.py — impact
  • tests/test_msbuild_dir_evidence.py — impact
  • tests/test_objc_field_table_remap.py — impact
  • tests/test_out_dir_evidence.py — impact
  • tests/test_partial_cache.py — impact
  • tests/test_pipeline.py — impact
  • tests/test_python_inherited_method_calls.py — impact
  • tests/test_python_injected_factory_calls.py — impact
  • tests/test_python_property_reads.py — impact
  • tests/test_python_pytest_fixture_receivers.py — impact
  • tests/test_rust_self_member_calls.py — impact
  • tests/test_rust_use_trees.py — impact
  • tests/test_semantic_cache_basename_recovery.py — impact
  • tests/test_semantic_cache_out_root.py — impact
  • tests/test_skill_persisted_scan_options.py — impact
  • tests/test_skill_semantic_all_cached.py — impact
  • tests/test_skillgen.py — impact
  • tests/test_slice_checkpoint_completeness.py — impact
  • tests/test_stale_prune.py — impact
  • tests/test_stat_index_husk.py — impact
  • tests/test_stat_index_multi_root.py — impact
  • tests/test_stat_index_portability.py — impact
  • tests/test_terraform_modules.py — impact
  • … and 8 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.

Every flagged function

  • extract() in graphify/extract.py:11742 · 1284 callers, 78 callees: fans out to 78 callees (efferent coupling); 1284 callers depend on it (afferent coupling)

@safishamsi

Copy link
Copy Markdown
Member

Landed in 0.9.113 (now on PyPI) as 086d19f. Thanks for the fix, @Deepjyoti-Sarmah.

@safishamsi safishamsi closed this Nov 19, 2026
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.

2 participants