Forum > General

Possible codetools bug

(1/1)

440bx:
Hello,

Consider the following code:
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- program Codetools; uses  Windows  ;  { --------------------------------------------------------------------------- }{ DOS HEADER related types and constants                                      } const  IMAGE_DOS_SIGNATURE = $5a4d;                        { 'MZ'                  } {$ifndef MS_FIELD_NAMES}type  { _IMAGE_DOS_HEADER                                                         }   PIMAGE_DOS_HEADER   = ^TIMAGE_DOS_HEADER;  TIMAGE_DOS_HEADER   = packed record    Signature              : word;    BytesOnLastPage        : word;    PageCount              : word;    RelocationsCount       : word;    HeaderInParagraphs     : word;    ExtraParagraphsNeeded  : word;    MaximumMemory          : word;    InitialSS              : word;    InitialSP              : word;    Checksum               : word;    InitialIp              : word;    InitialCs              : word;    RelocationsTableOffset : word;    OverlayNumber          : word;    ReservedWordsA         : packed array[0..3] of word;    OEMidentifier          : word;    OEMinformation         : word;    ReservedWordsB         : packed array[0..9] of word;    OffsetToNewExecutable  : DWORD;  end;{$endif}  {$ifdef MS_FIELD_NAMES}                               {  winnt.h field names  }type  { _IMAGE_DOS_HEADER                                                         }   PIMAGE_DOS_HEADER   = ^TIMAGE_DOS_HEADER;  TIMAGE_DOS_HEADER   = packed record    e_magic                : word;    e_cblp                 : word;    e_cp                   : word;    e_crlc                 : word;    e_cparhdr              : word;    e_minalloc             : word;    e_maxalloc             : word;    e_ss                   : word;    e_sp                   : word;    e_csum                 : word;    e_ip                   : word;    e_cs                   : word;    e_lfarlc               : word;    e_ovno                 : word;    e_res                  : packed array[0..3] of word;    e_oemid                : word;    e_oeminfo              : word;    e_res2                 : packed array[0..9] of word;    e_lfanew               : DWORD;  end;{$endif}  var ImageDosHeader : PIMAGE_DOS_HEADER = nil; ImageNtHeaders : pointer           = nil; begin  { don't try to run this... it won't                                         }   ImageNtHeaders := ImageDosHeader + ImageDosHeader^end.goto line 80, type a dot after ImageDosHeader^ and codetools will offer to complete with a set of fields that is not active, i.e, if you select e_lfanew and try to compile, there will be a compile error.  (see attachment)

if it is completed with "OffsetToNewExecutable" (which is _not_ offered by Codetools) then the compile will be successful.

Comments welcome.

Lazarus v3.99 (not the current trunk)

rvk:

--- Quote from: 440bx on November 06, 2024, 12:03:48 pm ---Comments welcome.

--- End quote ---
The autocomplete is (somewhat) correct.
You can check this by setting the cursor on ImageDosHeader^.
Press Alt+Up.
Set the cursor on the type PIMAGE_DOS_HEADER and press Alt+Up.
Set the cursor on the type ^TIMAGE_DOS_HEADER and press Alt+Up.

Then you see you end up in struct.inc.

So you have this line and expect the ^TIMAGE_DOS_HEADER points to YOUR new TIMAGE_DOS_HEADER.
But is doesn't. It points to the TIMAGE_DOS_HEADER in struct.inc according to the autocompleter (which isn't actually correct).

Why are you redefining types and not renaming them?
Now you have two TIMAGE_DOS_HEADER in your project (which gets confusing).
Rename it to something else and you have no problems.

I agree... the autocompleter should look at forward definition before going down the tree... but it gets confused by the already defined definition.

BTW. So it's not only the autocompleter but also the code-browser (Alt+Up etc) which does this incorrectly (but maybe those are the same ;) ).

440bx:

--- Quote from: rvk on November 06, 2024, 12:50:27 pm ---Why are you redefining types and not renaming them?
Now you have two TIMAGE_DOS_HEADER in your project (which gets confusing).
Rename it to something else and you have no problems.

--- End quote ---
I agree.

I normally use my own API definitions which includes (and exceeds) those found in Windows.pas but, I was writing a little test program and in that test program, I used the "standard" Windows but needed _my_ image definitions which is how I ended up with the double definition of IMAGE_DOS_HEADER.

IOW, in my non-test code, there is no "Windows", therefore the problem does not occur in that code.

Martin_fr:
https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/31230

440bx:

--- Quote from: Martin_fr on November 06, 2024, 01:40:53 pm ---https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/31230

--- End quote ---
Thanks.  Good to know it is a bug and it has been reported.

Navigation

[0] Message Index

Go to full version