Skip to content

fix(vbnet): skip comments and string literals in the call scan - #826

Merged
zzet merged 2 commits into
zzet:mainfrom
drakeo338:claude/809-fix
Sep 28, 2026
Merged

zzet merged 2 commits into
zzet:mainfrom
drakeo338:claude/809-fix

Conversation

@drakeo338

Copy link
Copy Markdown
Contributor

Summary

Fixes #809. The VB.NET call-scan regexes ran over the raw source, so call-shaped text inside '/REM comments and string literals (e.g. ' obj.Delete() or "client.Delete(") was emitted as real CALLS edges.

Changes

  • Add vbMaskCommentsAndStrings, which blanks comments and string/interpolated-string contents to spaces (keeping newlines and byte offsets intact) before the New, qualified-call and Call-statement regexes run over it.
  • Real call sites are still read from the original source, so names, lines and offsets are unaffected.
  • Add regression tests covering apostrophe comments, REM comments, and string literals (including escaped quotes) alongside a real call in the same method.

Testing

  • All tests pass (go test -race ./...)
  • New tests added for new functionality
  • Benchmarks run if performance-relevant

Checklist

  • Code follows existing patterns in the codebase
  • No unnecessary abstractions added
  • Language extractor includes Meta["methods"] for interfaces (if applicable)
  • Methods have EdgeMemberOf edges to their containing type (if applicable)

The qualified-call, Call-statement and New regexes ran over the raw
source, so `' client.Delete()`, `REM x.Purge()` and "x.Drop(" in a
string each produced a CALLS edge, and a commented-out `New Foo.Bar()`
produced a type reference. Those edges feed blast-radius queries.

The three scans now run over a same-length copy with comments and
string literals blanked, keeping newlines so offsets and line numbers
still index the original. REM counts only where a statement starts,
so Remote.Connect() stays a call, and an apostrophe inside a string
does not open a comment. Holes in interpolated strings stay visible,
so a call in $"{order.GetTotal()}" is still recorded.

Fixes zzet#809

@zzet zzet left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Hey @drakeo338, thank you for your contribution!

Overall looks good, but one moment missed: Inline REM comments are not masked. In vbMaskCommentsAndStrings, REM is recognized only at a statement start or after :. VB.NET also permits REM directly after another statement, separated by whitespace. Microsoft’s documentation even shows this form:

`MsgBox(statusMessage) REM Inform operator of status.`

Therefore:

`client.Save() REM client.Delete()` still emits a false `Delete` call edge.

Recognize REM outside strings whenever it is an exact, case-insensitive token with valid boundaries—preceded by whitespace, newline, :, or start-of-file, and followed by whitespace or EOF. Add a regression asserting Save exists and Delete does not.

REM was only recognised at the start of a statement, so the documented
form `client.Save() REM client.Delete()` still produced a Delete call
edge. REM now opens a comment wherever it is a whole token outside a
string: preceded by the start of input, whitespace or `:`, and followed
by whitespace or the end of input.
@drakeo338

Copy link
Copy Markdown
Contributor Author

Pushed 5a65b89: REM is now recognized after any whitespace, newline or :, not just at statement start, with a test proving client.Save() REM client.Delete() keeps Save and drops Delete.

@zzet
zzet merged commit e09c0f2 into zzet:main Sep 28, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VB.NET extractor emits CALLS edges from comments and string literals

2 participants