Closed zaneduffield closed 5 months ago
I should note that this example program does compile for me, with Delphi 11.2.
Also worth noting is the fact that the example doesn't compile if the parentheses are removed:
program Example;
begin
procedure(a: String) begin end('');
end.
Also, this issue is still present when the procedure isn't called:
begin
var proc := (procedure begin end);
end.
It seems that the expression parsing needs a little tweaking
When an assignment expression is parsed, it specifically allows an anonymous method to be the RHS:
https://github.com/integrated-application-development/sonar-delphi/blob/bd8a080a2f27e19852c76c5a7b5255e8c2d06781/delphi-frontend/src/main/antlr3/au/com/integradev/delphi/antlr/Delphi.g#L884
and similarly for inline var
https://github.com/integrated-application-development/sonar-delphi/blob/bd8a080a2f27e19852c76c5a7b5255e8c2d06781/delphi-frontend/src/main/antlr3/au/com/integradev/delphi/antlr/Delphi.g#L851
However, when parsing parenthesised expressions it just uses the plain expression
fragment:
https://github.com/integrated-application-development/sonar-delphi/blob/bd8a080a2f27e19852c76c5a7b5255e8c2d06781/delphi-frontend/src/main/antlr3/au/com/integradev/delphi/antlr/Delphi.g#L719
I don't know if the best way to fix this is to allow an anonymous procedure to be a first-class expression
, or if we just need to add a special case for parenthesised expressions to include anonymous procedures.
Based on your example, we should probably promote anonymous methods to proper expressions in the grammar.
Prerequisites
SonarDelphi version
1.4.0
SonarQube version
No response
Issue description
When an anonymous procedure literal is called directly, sonar-delphi fails to parse it.
Steps to reproduce
Scan the following delphi program
and observe the error
Minimal Delphi code exhibiting the issue
No response