Recent

Author Topic: unexpected added extra functions  (Read 5888 times)

Paolo

  • Full Member
  • ***
  • Posts: 227
unexpected added extra functions
« on: August 13, 2021, 08:11:05 pm »
Dear All,

at the moment I am not able to isolate the problem, but it is the second time I see this happening in some application of mine and at the moment it is sistematic.

simply adding a design time a button in my application, and generating the sckeleton of "onclick" events, the compiler generates some function duplicates with empty code, the affected routines are the same each time, I know that these are not meaningful information, but any insight on what can be happening is appreciated.

just for example, at the begin  I have:

Code: Pascal  [Select][+][-]
  1. type
  2.   TForm1 = class(TForm)
  3.   private
  4.  
  5.   public
  6.     procedure A(xx...);
  7.     procedure B(xx...);
  8.   end;
  9.  
  10. var
  11.   Form1: TForm1;
  12.  
  13. implementation
  14.  
  15. {$R *.lfm}
  16. procedure TForm1.A(xx...);
  17. begin
  18.   //do something
  19. end;
  20.  
  21. procedure TForm1.B(xx...);
  22. begin
  23.   //do something
  24. end;
  25.  
  26.  

after adding a TButton and clicking on object inspector to create the onclick event the code becames,

Code: Pascal  [Select][+][-]
  1.   TForm1 = class(TForm)
  2.     procedure Button1Click(Sender: TObject);
  3.   private
  4.  
  5.   public
  6.     procedure A(xx...);
  7.     procedure B(xx...);
  8.   end;
  9.  
  10. var
  11.   Form1: TForm1;
  12.  
  13. implementation
  14.  
  15. {$R *.lfm}
  16.  
  17. { TForm1 }
  18.  
  19. procedure TForm1.A(xx...); <-- duplicated
  20. begin
  21.   //EMPTY
  22. end;
  23.  
  24. procedure TForm1.B(xx...); <-- duplicted
  25. begin
  26.   //EMPTY
  27. end;
  28.  
  29. procedure TForm1.A(xx...);
  30. begin
  31.   //do something
  32. end;
  33.  
  34. procedure TForm1.B(xx...);
  35. begin
  36.   //do something
  37. end;
  38.  
  39. procedure TForm1.Button1Click(Sender: TObject);
  40. begin
  41.  
  42. end;
  43.  
  44.  

then the compiler warning was : "ERROR: overloaded functions have the same parameter list"

win-10 64bit, LAZ 2.0.12, fpc 3.2.0

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 7508
  • Debugger - SynEdit - and more
    • wiki
Re: unexpected added extra functions
« Reply #1 on: August 13, 2021, 08:34:57 pm »
Some general info / this is not my area of expertise....

IIRC the issue has been mentioned before (maybe even a bug reported, not sure / you might want to check).
But without exact steps, how to reproduce, it will be hard to track.

1) Does it always happen.
Can you freshly load your project, and make it happen at will?
Or does it only happen after you worked for a while in the IDE?

2) menu: view > ide internals > view codetool node info.
Once it happen immediately get all the info (from all tabs) for the unit in which it happens (the unit must be the active editor when you go to the menu)

For all else, someone with experience on the codetools has to look at.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 7508
  • Debugger - SynEdit - and more
    • wiki
Re: unexpected added extra functions
« Reply #2 on: August 13, 2021, 08:40:03 pm »
My personal guess. Just a very wild guess....

It may be that codetool assumes the end of the file before the existing declaration.

It could be that this is related to an issue I observed.
Invoking code navigation on a word in a comment sometimes leaves code after the comment unreachable to codetools. Normally however this will give errors, rather that performing a wrong action.

In any case, it might be worth to pay attention to any codetool invocation (hint, navigation, completion,...) inside a comment.



Paolo

  • Full Member
  • ***
  • Posts: 227
Re: unexpected added extra functions
« Reply #3 on: August 13, 2021, 08:46:21 pm »
thanks Martin,

Quote
But without exact steps, how to reproduce, it will be hard to track.
Yes, I know, I have to try to isolate the cause in a smaller project

Quote
1) Does it always happen.
Can you freshly load your project, and make it happen at will?
Or does it only happen after you worked for a while in the IDE?
Always. Very reproducible. It happens at the any moment I'll try to add a button event (not checked for other components..)
Quote

2) menu: view > ide internals > view codetool node info.
Once it happen immediately get all the info (from all tabs) for the unit in which it happens (the unit must be the active editor when you go to the menu)
I'll check. the form where it happens is the main form and it is the one on which I put the button.

Some other info:
- project ported from Delphi code
- the routines affected have a large amount of parameters in their declaration.
« Last Edit: August 14, 2021, 08:49:51 am by Paolo »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 7508
  • Debugger - SynEdit - and more
    • wiki
Re: unexpected added extra functions
« Reply #4 on: August 13, 2021, 08:50:13 pm »
If you know it will happen, then also get the "codetool node info" immediately before.

jamie

  • Hero Member
  • *****
  • Posts: 5011
Re: unexpected added extra functions
« Reply #5 on: August 13, 2021, 10:33:57 pm »
That problem has been around for a long time now..

I turn on the feature in the IDE to remove empty methods.

But, it shouldn't be doing that of course. I didn't put much time into finding the issue but it seems to be random or some pattern of methods already existing that is causing it.

  Maybe a search for existing methods are failing?
The only true wisdom is knowing you know nothing

Paolo

  • Full Member
  • ***
  • Posts: 227
Re: unexpected added extra functions
« Reply #6 on: August 14, 2021, 08:49:26 am »
@Martin,
attached my "View" menu, sorry it was in Italian language, where is "view > ide internals > view codetool node info" ?

Paolo

  • Full Member
  • ***
  • Posts: 227
Re: unexpected added extra functions
« Reply #7 on: August 14, 2021, 07:16:06 pm »
SOLVED !

here how ot reproduce the problem. Look at the code below

Code: Pascal  [Select][+][-]
  1.  
  2.   TForm1 = class(TForm)
  3.   private
  4.  
  5.   public
  6.     procedure PROC2(ANumX, ANumY: integer; AOffsdB: double;
  7.                     var AMaxdB, AMaxDeg : double;
  8.                     var AXMax, AYMax : double;
  9.                     var AThMax, AFiMax: double);
  10.   end;
  11.  
  12. var
  13.   Form1: TForm1;
  14.  
  15. implementation
  16.  
  17. {$R *.lfm}
  18.  
  19. procedure TForm1.PROC2(ANumX, ANumY: integer; AOffsdB: double;
  20.                        var AMaxdB, AMaxDeg, AXMax, AYMax, AThMax, AFiMax: double);
  21. begin
  22. end;
  23.  

It compiles, but... look at the PROC2 declaration "TFrom1.PROC2" where several variables are declared by unique "var", whereas in the first declaration PROC2 has several  "var" used.

when add a "TButton" e doubleclick on it to create the click event, the editor is so smart to create the missed declaration with all the "var", and the code becomes as follow

Code: Pascal  [Select][+][-]
  1.  
  2.   TForm1 = class(TForm)
  3.     Button2: TButton;
  4.     procedure Button2Click(Sender: TObject);
  5.   private
  6.  
  7.   public
  8.     procedure PROC2(ANumX, ANumY: integer; AOffsdB: double;
  9.                     var AMaxdB, AMaxDeg : double;
  10.                     var AXMax, AYMax : double;
  11.                     var AThMax, AFiMax: double);
  12.   end;
  13.  
  14. var
  15.   Form1: TForm1;
  16.  
  17. implementation
  18.  
  19. {$R *.lfm}
  20.  
  21. procedure TForm1.PROC2(ANumX, ANumY: integer; AOffsdB: double;
  22.                        var AMaxdB, AMaxDeg, AXMax, AYMax, AThMax, AFiMax: double);
  23. begin
  24. end;
  25.  
  26. procedure TForm1.Button2Click(Sender: TObject);
  27. begin
  28.  
  29. end;
  30.  
  31. procedure TForm1.PROC2(ANumX, ANumY: integer; AOffsdB: double; var AMaxdB,
  32.   AMaxDeg: double; var AXMax, AYMax: double; var AThMax, AFiMax: double);
  33. begin
  34.  
  35. end;
  36.  

and finally you have two procedures and the "ERROR: overloaded functions have the same parameter listimplemenation".

Probably the implementation section was edited-by-hand and the multiple var omitted, but please note that all works fine (and this is conceptually right).
However, It should be a bug, either because not exactly equal declaration is implemented in the two sections or because the editor does not recognize that the two declarations are essentially the same (I propend for the first option...).

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 7508
  • Debugger - SynEdit - and more
    • wiki
Re: unexpected added extra functions
« Reply #8 on: August 14, 2021, 07:57:51 pm »
1) Was the existing body generated by codetools from the existing header? Or were they edited by hand, so they looked different?

2) Please report on the bug-tracker.

Paolo

  • Full Member
  • ***
  • Posts: 227
Re: unexpected added extra functions
« Reply #9 on: August 14, 2021, 08:33:29 pm »
Quote
« Reply #8 on: Today at 07:57:51 pm »
Quote
1) Was the existing body generated by codetools from the existing header? Or were they edited by hand, so they looked different?

I spose by hand, but later I'll check also the codetool behaviour
Quote
« Reply #8 on: Today at 07:57:51 pm »
Quote
2) Please report on the bug-tracker
Ok, I'll check how, it is the first time.
However it remain not clear why the editor create the supposed missed procedure body once the tbutton onclick is placed in the code (it should just said "missed procedure body")
« Last Edit: August 14, 2021, 08:37:16 pm by Paolo »

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3996
  • I like bugs.
Re: unexpected added extra functions
« Reply #10 on: August 14, 2021, 08:52:56 pm »
2) Please report on the bug-tracker.
No need to report. It is a knows issue and is already reported. I try to find the issue...

This is similar although not exactly the same :
 https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/35413

This modifies the implementation signature although the summary says it duplicates.
 "Code completion duplicates method implementation"
 https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/18793

Is there no report about the duplicated handler? I remember there was.
Maybe this example case could be added to #18793. Its summary sounds right.
« Last Edit: August 14, 2021, 09:12:57 pm by JuhaManninen »
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

Paolo

  • Full Member
  • ***
  • Posts: 227
Re: unexpected added extra functions
« Reply #11 on: August 15, 2021, 12:27:58 pm »
just one note more.
If the code is as below, (where two procedure declarations have different "form", but it complies and works)

Code: Pascal  [Select][+][-]
  1. type
  2.   TForm1 = class(TForm)
  3.   private
  4.  
  5.   public
  6.     procedure PROC2(ANumX, ANumY: integer; AOffsdB: double;
  7.                     var AMaxdB, AMaxDeg : double;
  8.                     var AXMax, AYMax : double;
  9.                     var AThMax, AFiMax: double);
  10.   end;
  11.  
  12. var
  13.   Form1: TForm1;
  14.  
  15. implementation
  16.  
  17. {$R *.lfm}
  18.  
  19. procedure TForm1.PROC2(ANumX, ANumY: integer; AOffsdB: double; var AMaxdB,
  20.   AMaxDeg, AXMax, AYMax, AThMax, AFiMax: double);
  21. begin
  22.  
  23. end;
  24.  
  25.  

and ctrl+shift+C si done on the first procedure declaration, no added extra procedure is created, but the second declaration is updated accordingly to the first declaration

Code: Pascal  [Select][+][-]
  1.  
  2.   TForm1 = class(TForm)
  3.   private
  4.  
  5.   public
  6.     procedure PROC2(ANumX, ANumY: integer; AOffsdB: double;
  7.                     var AMaxdB, AMaxDeg : double;
  8.                     var AXMax, AYMax : double;
  9.                     var AThMax, AFiMax: double);
  10.   end;
  11.  
  12. var
  13.   Form1: TForm1;
  14.  
  15. implementation
  16.  
  17. {$R *.lfm}
  18.  
  19. { TForm1 }
  20.  
  21. procedure TForm1.PROC2(ANumX, ANumY: integer; AOffsdB: double; var AMaxdB,
  22.   AMaxDeg: double; var AXMax, AYMax: double; var AThMax, AFiMax: double);
  23. begin
  24.  
  25. end;
  26.  

 

TinyPortal © 2005-2018