Recent

Author Topic: FPC bug? var h: integer; h = nil?  (Read 4928 times)

anyeos

  • New Member
  • *
  • Posts: 13
FPC bug? var h: integer; h = nil?
« on: April 11, 2014, 07:34:42 pm »
I don't have the time to report it to bugfile or to check if it is already solved (but I guess it is not solved because the naturity of it).

When I define records like this:

Code: [Select]
  TRect = record
x: integer;
  y: integer;
  w: integer;
  h: integer;
  End;

I declare a var:
Code: [Select]
Var
  rectangle: TRect;

And when I try to assign values:

Code: [Select]
begin
  rectangle.x := 10;
  rectangle.y := 20;
  rectangle.w := 50;
  rectangle.h := 60; 
end;

A breakpoint in the beginning of the assignment pause the program in that place. Then I evaluate the values and guess what:

Quote
rectangle.h = Type TRECT has no component named h.

Sometimes in some uncommon situation assigning a value to h in any record or class what have a h name gives me a SIGSEGV.
The special case is with SDL2 calling SDL_RenderCopy or SDL_RenderCopyEx where that functions try to assign values to a TSDL_Rect type, specially in the h component.


In a near finished work/program that I am developing when I use intensively types like the TRect declared above, I give a lot of "Type <kind of type> has no component named h" or sometimes a problem with the name y too (I don't remember now if it is the same problem, but appears to be related).
And that don't let me evaluate or modify the "h" named fields.

It appears that h is used internally? Or the compiler for some reason is confusing the h with something other thing.

If I use complete names like "height":

Code: [Select]
  TRect = record
  x: integer;
    y: integer;
    width: integer;
    height: integer;
  End;
     

It works as expected. It shows the values.

But If I declare h alone:
Code: [Select]
Var
  h : integer;


And in the breakpoint code:

Code: [Select]
h := 135;
The evaluate/modify says: h = nil

How that can be possible? H is integer! not pointer! how it can be nil?

If I try to assign a nil value to some integer type I get the error:
'Error: Incompatible types: got "Pointer" expected "Longint"

So, something is wrong in FPC using the name 'h'.

Is h some reserved var? As I know is not.

What is happening then?

howardpc

  • Hero Member
  • *****
  • Posts: 3097
Re: FPC bug? var h: integer; h = nil?
« Reply #1 on: April 11, 2014, 07:47:33 pm »
You are redefining the TRect type (defined in the types unit) which is used extensively in a GUI environment such as the LCL.
Because use of TRect is so widespread in FCL/LCL source code, you may not need
Code: [Select]
uses types;
anywhere explicitly in your code for the compiler and codetools to know it and assume use of types.TRect rather than your redefined TRect version.
Better to rename your type as TMyRect (or almost anything other than TRect). That will solve your problem immediately.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5573
    • wiki
Re: FPC bug? var h: integer; h = nil?
« Reply #2 on: April 11, 2014, 08:18:08 pm »
There are several issues that you describe.

On one side there are issues with code not compiling, or crashing.
On the other side there are issues with the debugger.

I can try to help with the latter. (And in fact woul like to know more about them, in order to see, if they can be fixed or not)

However from the samples you gave, I can not reproduce any of them.

You can either get me the full source (and project settings, and then hopefully, I can reproduce the issue).

Or you can generate a log please (Or do both).
Logs:
http://wiki.lazarus.freepascal.org/GDB_Debugger_Tips#Log_info_for_debug_session

The only known issue with the debugger and record types (and it would apply to cases where several different declarations with the same name apply) is
   array [] of record

(Maybe it also applies to var param / not sure)


---
Also ensure your setup: http://wiki.lazarus.freepascal.org/Debugger_Setup