Skip to content

fix(pascal): detect unqualified paren-less calls (DoWork;) - #1641

Open
equipados wants to merge 1 commit into
colbymchenry:mainfrom
equipados:fix/pascal-unqualified-parenless-calls
Open

fix(pascal): detect unqualified paren-less calls (DoWork;)#1641
equipados wants to merge 1 commit into
colbymchenry:mainfrom
equipados:fix/pascal-unqualified-parenless-calls

Conversation

@equipados

Copy link
Copy Markdown

What

A Pascal statement that is nothing but an identifier — DoWork; — is an
unqualified call to a parameterless routine. visitPascalBlock didn't treat it
as one, so only the parenthesised form DoWork() produced a calls edge.

Pascal lets a no-arg routine drop its parens, and in Delphi that is the
convention rather than the exception, so on a real Delphi codebase most
intra-unit calls were invisible to callers / callees / impact. Those tools
didn't return a wrong answer — they returned an empty one, which is harder to
notice.

The qualified form (Obj.Free;) is already handled by
extractPascalParenlessCall (thanks — that landed in 1.5). This is the same
idea one step less qualified.

Measured on a real Delphi codebase

285 .pas/.dpr files from a production Delphi 10.2 ERP (~1.1M LOC):

calls edges
1.5.0 as-is 2316
with this patch 2711
+395 (+17%)

How it's scoped

Gated on the identifier being the whole statement:

child.type === 'identifier' &&
node.type === 'statement' &&
node.namedChildCount === 1

Anywhere else — assignment RHS, if condition, any expression — a bare
identifier is indistinguishable from a variable read without type information,
so those are deliberately left alone. That is what the second test locks in:

procedure TFoo.DoThing;
var
  Total, Other: Integer;   // and TFoo has a method also called Total
begin
  Other := Total;                    // variable read, NOT a call
  if Total > 0 then Other := 0;      // variable read, NOT a call
end;

isCalled('TFoo::Total') must stay false.

Tests

Two added next to the existing paren-less test in
__tests__/resolution.test.ts:

  • extracts UNQUALIFIED paren-less calls (Reset;, the dominant Delphi idiom) — fails without the change, passes with it.
  • does not turn a bare identifier that is NOT a whole statement into a call — the negative case above.

resolution.test.ts + extraction.test.ts: 788 passed. The 5 failures on my
machine (3× PHP include, 1× C/C++ include, 1× gitlink) are identical before and
after the change — pre-existing and unrelated, likely Windows-specific.

tsc --noEmit clean.

Notes

Only src/extraction/tree-sitter.ts changes; Pascal is not part of the Rust
kernel so there is no parity fixture to update.

A statement that is nothing but an identifier is an unqualified call to a
parameterless routine. Pascal allows dropping the parens on a no-arg call and
Delphi codebases do so by convention, so `visitPascalBlock` was missing the
majority of intra-unit calls: only `DoWork()` was recorded, never `DoWork;`.

The qualified form (`Obj.Free;`) is already handled by
`extractPascalParenlessCall`; this is the same idea one step less qualified.

Gated on the identifier BEING the whole statement (`node.type === 'statement'
&& node.namedChildCount === 1`). Anywhere else — assignment RHS, condition, any
expression — a bare identifier is indistinguishable from a variable read
without type information, so those are left alone. Covered by a negative test.
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.

1 participant