fix(vbnet): skip comments and string literals in the call scan - #826
Conversation
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
left a comment
There was a problem hiding this comment.
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.
|
Pushed 5a65b89: REM is now recognized after any whitespace, newline or |
Summary
Fixes #809. The VB.NET call-scan regexes ran over the raw source, so call-shaped text inside
'/REMcomments and string literals (e.g.' obj.Delete()or"client.Delete(") was emitted as realCALLSedges.Changes
vbMaskCommentsAndStrings, which blanks comments and string/interpolated-string contents to spaces (keeping newlines and byte offsets intact) before theNew, qualified-call andCall-statement regexes run over it.REMcomments, and string literals (including escaped quotes) alongside a real call in the same method.Testing
go test -race ./...)Checklist
Meta["methods"]for interfaces (if applicable)EdgeMemberOfedges to their containing type (if applicable)