[fpc-pascal] Specializing generics in a generic

bartek bbartek at gmx.net
Thu Dec 27 00:36:31 CET 2007


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] bartek at banana:~/Dev/Tests
% 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.



More information about the fpc-pascal mailing list