Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2009-10

Errors using generics - what is wrong?

9 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Žilvinas Ledas

Hello all,

I am trying to use generics but compilation fails. Whan I try to use unit with my generic class in my real project I get "Fatal: Internal error 200204175" error.
When I try to use it in empty Lazarus application (Unit1.pas) and I put -----
procedure TForm1.Button1Click(Sender: TObject);
var

  lst:  specialize TTwoValuesList<UnicodeString>;

begin
end;
-----
I get these errors:
-----
Unit1.pas(29,17) Error: Forward declaration not solved "constructor TTwoValuesList$UnicodeString.Create;"
Unit1.pas(30,16) Error: Forward declaration not solved "destructor TTwoValuesList$UnicodeString.Destroy;"
Unit1.pas(32,15) Error: Forward declaration not solved "TTwoValuesList$UnicodeString.AddString(UnicodeString,UnicodeString);" Unit1.pas(33,14) Error: Forward declaration not solved "TTwoValuesList$UnicodeString.GetS1(LongInt):UnicodeString;" Unit1.pas(34,14) Error: Forward declaration not solved "TTwoValuesList$UnicodeString.GetS2(LongInt):UnicodeString;" Unit1.pas(35,14) Error: Forward declaration not solved "TTwoValuesList$UnicodeString.Count:LongInt;"
Unit1.pas(36,14) Error: Forward declaration not solved "TTwoValuesList$UnicodeString.GetS2(UnicodeString,Boolean="FALSE"):UnicodeString;" Unit1.pas(47) Fatal: There were 7 errors compiling module, stopping -----

my generic class is in another (not Unit1.pas) unit looks like this:
-----
type
  generic TTwoValuesList<TVal> = class
  type private
    PTwoVal = ^TTwoVal;
    TTwoval = record
      FS1: TVal;
      FS2: TVal;
    end;
  var private
    FLst: TFPList;
  public
    constructor Create;
    destructor Destroy;
    procedure AddString(S1: TVal; S2: TVal);
    function GetS1(i: Integer): TVal;
    function GetS2(i: Integer): TVal; overload;
    function Count: Integer;
    function GetS2(S1: TVal; isSorted: Boolean = false): TVal; overload;
  published
    property Items: TFPList read FLst;
  end;
-----

What am I doing wrong?

Regards,
Zilvinas Ledas

Reply by email

Žilvinas Ledas
to Žilvinas Ledas

Sorry, I forgot to mention I am using
Free Pascal Compiler version 2.3.1 [2009/09/08] for i386 (don't know how to get more specific version info...)

Žilvinas Ledas wrote 72 lines
Hello all, I am trying to use generics but compilation fails. Whan I try to use unit with my generic class in my real project I get "Fatal: Internal error 200204175" error. When I try to use it in empty Lazarus application (Unit1.pas) and I put ----- procedure TForm1.Button1Click(Sender: TObject); var lst: specialize TTwoValuesList<UnicodeString>; begin end; ----- I get these errors: ----- Unit1.pas(29,17) Error: Forward declaration not solved "constructor TTwoValuesList$UnicodeString.Create;" Unit1.pas(30,16) Error: Forward declaration not solved "destructor TTwoValuesList$UnicodeString.Destroy;" Unit1.pas(32,15) Error: Forward declaration not solved "TTwoValuesList$UnicodeString.AddString(UnicodeString,UnicodeString);" Unit1.pas(33,14) Error: Forward declaration not solved "TTwoValuesList$UnicodeString.GetS1(LongInt):UnicodeString;" Unit1.pas(34,14) Error: Forward declaration not solved "TTwoValuesList$UnicodeString.GetS2(LongInt):UnicodeString;" Unit1.pas(35,14) Error: Forward declaration not solved "TTwoValuesList$UnicodeString.Count:LongInt;" Unit1.pas(36,14) Error: Forward declaration not solved "TTwoValuesList$UnicodeString.GetS2(UnicodeString,Boolean="FALSE"):UnicodeString;" Unit1.pas(47) Fatal: There were 7 errors compiling module, stopping ----- my generic class is in another (not Unit1.pas) unit looks like this: ----- type generic TTwoValuesList<TVal> = class type private PTwoVal = ^TTwoVal; TTwoval = record FS1: TVal; FS2: TVal; end; var private FLst: TFPList; public constructor Create; destructor Destroy; procedure AddString(S1: TVal; S2: TVal); function GetS1(i: Integer): TVal; function GetS2(i: Integer): TVal; overload; function Count: Integer; function GetS2(S1: TVal; isSorted: Boolean = false): TVal; overload; published property Items: TFPList read FLst; end; ----- What am I doing wrong? Regards, Zilvinas Ledas _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email

Vincent Snijders
to Žilvinas Ledas: I am trying to use generics but compilation fails. Whan I try to use unit with my generic…
Žilvinas Ledas wrote 15 lines
Hello all, I am trying to use generics but compilation fails. Whan I try to use unit with my generic class in my real project I get "Fatal: Internal error 200204175" error. When I try to use it in empty Lazarus application (Unit1.pas) and I put ----- procedure TForm1.Button1Click(Sender: TObject); var lst: specialize TTwoValuesList<UnicodeString>; begin end; ----- I get these errors: -----
I would try to use a named type:
type
   TTwoUnicodeValuesList = specialize TTwoValuesList<UnicodeString>;
procedure TForm1.Button1Click(Sender: TObject);
var
  lst:  TTwoUnicodeValuesList;
begin
end;

Vincent

Reply by email

Žilvinas Ledas
to Vincent Snijders
Vincent Snijders wrote 13 lines
I would try to use a named type: type TTwoUnicodeValuesList = specialize TTwoValuesList<UnicodeString>; procedure TForm1.Button1Click(Sender: TObject); var lst: TTwoUnicodeValuesList; begin end; Vincent

Thanks, it works with named type.
Is using not named specializations is some kind of "not implemented yet" part? :)

Regards
Zlvinas Ledas

Reply by email

Micha Nelissen
to Žilvinas Ledas
Žilvinas Ledas wrote
Thanks, it works with named type. Is using not named specializations is some kind of "not implemented yet" part? :)

No it's a design choice to more easily reuse separate (but equal) specializations.

Micha

Reply by email

Tomas Hajny
to Micha Nelissen
Micha Nelissen wrote 7 lines
Žilvinas Ledas wrote: > Thanks, it works with named type. > Is using not named specializations is some kind of "not implemented yet" > part? :) No it's a design choice to more easily reuse separate (but equal) specializations.

Well, the internal error is in any case a bug, so if this appears also with the latest (trunk) version, a bug report would be useful.

Tomas

Reply by email

Micha Nelissen
to Tomas Hajny
Tomas Hajny wrote
Well, the internal error is in any case a bug, so if this appears also with the latest (trunk) version, a bug report would be useful.

I didn't see an internal error? But a more descriptive message would be useful ('specialization not allowed in this context' or so?).

Micha

Reply by email

Tomas Hajny
to Micha Nelissen
Micha Nelissen wrote 6 lines
Tomas Hajny wrote: > Well, the internal error is in any case a bug, so if this appears also > with the latest (trunk) version, a bug report would be useful. I didn't see an internal error? But a more descriptive message would be useful ('specialization not allowed in this context' or so?).

The original post mentioned "Fatal: Internal error 200204175".

Tomas

Reply by email

Žilvinas Ledas
to Tomas Hajny
Yes, I had an internal error and now I know why - I used specialization
in function params. This gives internal error:
procedure asdasd(something: specialize TTwoValuesList<UnicodeString>);
begin
end;

I'll make a bug report tomorow or a day after.

And yes, I think a descriptive message saying to use typed specialization would be nice for those using generics first time.

Regards,
Zilvinas

Tomas Hajny wrote 15 lines
On Wed, October 7, 2009 18:47, Micha Nelissen wrote: > Tomas Hajny wrote: > >> Well, the internal error is in any case a bug, so if this appears also >> with the latest (trunk) version, a bug report would be useful. >> > I didn't see an internal error? But a more descriptive message would be > useful ('specialization not allowed in this context' or so?). > The original post mentioned "Fatal: Internal error 200204175". Tomas

Reply by email