Sign in Join

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

Mailing lists / fpc-pascal / 2007-12

Specializing generics in a generic

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

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

bartek

Hi,

When i try to specialize generics in a generic, FPC wants me to give more types for specialization (of the containing generic) where IMO only one is needed.

The code:

{$mode objfpc} {$h+}
program test;
uses classes, sysutils;
type
        generic TNode<T> = class
        var
        public
                Data: T;
                constructor Create;
                destructor Destroy; override;
        end;
        generic TContainer<T> = class
        public
        type
                TTNode = specialize TNode<T>;
                TTNodeNode = specialize TNode<TTNode>;
                TTNodeNodeRec = record
                        ANode: TTNodeNode;
                end;
                TTNodeNodeRecNode = specialize TNode<TTNodeNodeRec>;
        var
        public
                Data: TTNodeNodeRecNode;
                constructor Create;
                destructor Destroy; override;
        end;
        TAContainer = specialize TContainer<Single>;
--------------------------------------------------^ (30, 51)
constructor TNode.Create;
begin
end;
destructor TNode.Destroy;
begin
        inherited Destroy;
end;
constructor TContainer.Create;
begin
end;
destructor TContainer.Destroy;
begin
        inherited Destroy;
end;
var
        AContainer: TAContainer;
begin
end.

[1049]
% fpc test.pp
Free Pascal Compiler version 2.3.1 [2007/12/27] for i386 Copyright (c) 1993-2007 by Florian Klaempfl
Target OS: Linux for i386
Compiling test.pp
test.pp(30,51) Fatal: Syntax error, "," expected but ">" found Fatal: Compilation aborted
Error: /usr/bin/ppc386 returned an error exitcode (normal if you did not specify a source file to be compiled)

Never having written any generic code i am not sure whether there is a problem in my code or in fpc. I hope somebody can enlighten me once again ;) Thank you in advance.

bartek.

Reply by email