[fpc-devel] Generics are still broken

JC Chu jcchu at acm.org
Fri May 11 18:19:30 CEST 2012


It will compile correctly with the trunk version.

Generics support has been greatly improved in the trunk version; you may
want to give it a try.

On May 12, at 00:11, Anthony Walter wrote:

> Generics still have a lot of problems.  I know they've been in the works
> for years but they still fail easily. Consider the Delphi mode below, I
> get "Error: Generics without specialization cannot be used as a type for
> a variable"
> 
> I could easily write up a whole bunch of test cases were generic still
> fail, both in Fpc and Delphi modes. If someone is considering working on
> the compiler to fix the problems with generics I can happily send them a
> bunch of test cases where the compiler currently fails.
> 
> {$mode delphi}
> 
> { TEnumerator<T> }
> 
> type
>   TEnumerator<T> = class abstract
>   protected
>     function DoGetCurrent: T; virtual; abstract;
>     function DoMoveNext: Boolean; virtual; abstract;
>   public
>     property Current: T read DoGetCurrent;
>     function MoveNext: Boolean;
>   end;
> 
> { TEnumerable<T> }
> 
>   TEnumerable<T> = class abstract
>   protected
>     function DoGetEnumerator: TEnumerator<T>; virtual; abstract; //
> Error: Generics without specialization cannot be used as a type for a
> variable
>   public
>     function GetEnumerator: TEnumerator<T>;
>   end; 
> 
> 
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-devel

-- 
Best regards,
JC Chu



More information about the fpc-devel mailing list