[fpc-devel] Problem (bug?) with generics

Giulio Bernardi ugilio at hotmail.com
Fri Sep 14 09:01:59 CEST 2007


> Never mind, it's in the lines before. Seems like fpc doesn't allow
> dereferencing a variable of a generic type in any way. The expression p^
> will generate the error.

Sorry I made the wrong example. The problem isn't in the dereferencing of 
the pointer,
but in accessing record fields. Here is simpler example:
==============================================
program genbug;

{$MODE OBJFPC}

uses
  Classes, SysUtils;

type
  TRec32 = packed record
    data1 : longword;
    data2 : longword;
  end;

  TRec64 = packed record
    data1 : qword;
    data2 : qword;
  end;

  generic TGenClass<_TRec_> = class
  public
    constructor Create;
  end;

  TClass32 = specialize TGenClass<TRec32>;
  TClass64 = specialize TGenClass<TRec64>;

  constructor TGenClass.Create;
  var rec : _TRec_;
  begin
    rec.data1:=1;
    rec.data2:=2;
  end;


begin

end.
==============================================

FPC complains in
    rec.data1:=1;
    rec.data2:=2;
because rec isn't fully defined, so it finds no field data1 or data2 in rec.
However, I think it should complain only if I try to specialize TGenClass 
with
a type that doesn't have data1 and data2 fields/members/properties.

So I am wondering if this is the correct behaviour, or if it is a bug, or if 
it
is something that is not implemented now but will be in the future.

bye,
Giulio 




More information about the fpc-devel mailing list