Skip to content

parsing error on method parameter declaration "cAdditionalSQL: IDictionary<string, string>=nil" #318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
2 tasks done
simonegirlanda opened this issue Dec 4, 2024 · 5 comments · Fixed by #335
Closed
2 tasks done
Assignees
Labels
bug Something isn't working

Comments

@simonegirlanda
Copy link

simonegirlanda commented Dec 4, 2024

Prerequisites

  • This bug is in SonarDelphi, not SonarQube or my Delphi code.
  • This bug has not already been reported.

SonarDelphi version

1.11.0

SonarQube version

10.7

Issue description

We had this error during parsing:

ERROR Error while analyzing D:\test\ant\test.pas au.com.integradev.delphi.file.DelphiFile$DelphiFileConstructionException: Failed to construct DelphiFile (line 7:21 no viable alternative at input '(')

adding spaces before the = sign in the parameter declaration will solve the problem

Steps to reproduce

try analyze the following code.
add spaces before and after the = sign (in the class Public methods declaration) to remove the error

Minimal Delphi code exhibiting the issue

Case 1

unit test;
Interface
Type
  TAnagrafica = Class(TObject)
   Public
    procedure GetSlaveItemsBad(cAdditionalSQL: IDictionary<string, string>=nil); // bad declaration --> generate parsing error
    procedure GetSlaveItemsGood(cAdditionalSQL: IDictionary<string, string> = nil); // good declaration --> no error  
  End;
Implementation
End.

another code example

In this case a 'missing FORWARD' message error is produced

unit testassignment;
interface
type
 myclass = Class(Tobject)
   Public
	Procedure myMethod;
 End;
 
Implementation


 Procedure myClass.myMethod;
 Var
    B : Boolean;
 const
  aEntityTableNames: tArray<string>=[EntityField_TableName,
                                    EntityAction_TableName,
                                    Linguaggio_TableName,
                                    Postazione_TableName,
                                    Config_EntityName,
                                    Utente_EntityName,
                                    Gruppo_TableName];	

Begin
End;
  
 end.
@simonegirlanda simonegirlanda added bug Something isn't working triage This needs to be triaged by a maintainer labels Dec 4, 2024
@zaneduffield
Copy link
Collaborator

My guess is that the >= is being tokenised as a greater-than-or-equal token, which explains why adding the spaces helps.

This is yet another argument in favour of #261 (and against tokenising before parsing).

@Cirras
Copy link
Collaborator

Cirras commented Dec 4, 2024

Agreed with @zaneduffield.
This is blocked by #261.

@Cirras Cirras removed the triage This needs to be triaged by a maintainer label Dec 4, 2024
@simonegirlanda
Copy link
Author

Added code example from #321

@LinriAB
Copy link

LinriAB commented Jan 17, 2025

Thanks @simonegirlanda, this topic seems a much better fit for the problems I'm having.

A few additional examples for this issue:

09:17:06.430 ERROR Error while processing C:\gitlab-runner\builds\sCyaQG4y\0\secura\administrator\Lib\Secura Lib\SecuraTable.pas
au.com.integradev.delphi.file.DelphiFile$DelphiFileConstructionException: Failed to construct DelphiFile (line 5765:35 mismatched input '>=' expecting GREATER_THAN)
at au.com.integradev.delphi.file.DelphiFile.setupFile(DelphiFile.java:161)
at au.com.integradev.delphi.file.DelphiFile.from(DelphiFile.java:136)
at au.com.integradev.delphi.symbol.SymbolTableBuilder.process(SymbolTableBuilder.java:288)
at au.com.integradev.delphi.symbol.SymbolTableBuilder.createImportDeclaration(SymbolTableBuilder.java:219)

09:17:07.478 ERROR Error while processing C:\gitlab-runner\builds\sCyaQG4y\0\secura\administrator\Lib\Secura Lib\pnglang2.pas
au.com.integradev.delphi.file.DelphiFile$DelphiFileConstructionException: Failed to construct DelphiFile (line 304:0 mismatched character '' expecting ''')

09:17:32.233 ERROR Error while processing C:\gitlab-runner\builds\sCyaQG4y\0\secura\administrator\Lib\Secura Lib\SecuraGrid.pas
au.com.integradev.delphi.file.DelphiFile$DelphiFileConstructionException: Failed to construct DelphiFile (line 223:21 no viable alternative at input '(')

@Cirras
Copy link
Collaborator

Cirras commented Jan 20, 2025

Hi @LinriAB,

Your first case is almost certainly an instance of this issue, but I'm not so sure about cases 2 and 3.

Can you isolate the problem a bit further, maybe share some snippets of code that reproduce those other errors?
That would help us determine if the additional cases need separate issues or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants