[Pas2js] Testing generics

Mattias Gaertner nc-gaertnma at netcologne.de
Wed Oct 23 18:40:45 CEST 2019


On Wed, 23 Oct 2019 06:19:51 -0700 (MST)
warleyalex via Pas2js <pas2js at lists.freepascal.org> wrote:

> class procedure issue in fpc mode.
> 
> I would like this code:
> ---------------------------------------------
> type
>   generic TGen<T> = record
>     class procedure Proc(item: T); static;
>   end;
> 
> generic class procedure TGen<T>.Proc(item: T);
> begin
>   //console.log(SizeOf(T));
>   if item > 0 then
>     WriteLn('Positive')
>   else if item < 0 then
>     WriteLn('Negative')
>   else
>     WriteLn('Zero');
> end;
> ---------------------------------------------
> begin
>   specialize TGen<LongInt>.Proc(0);       // Zero
>   specialize TGen<Int64>.Proc(123);       // Positive
>   specialize TGen<Extended>.Proc(-11);  // negative
> end;

This is not ObjFPC syntax. It must be:

type
  generic TGen<T> = record
    class procedure Proc(item: T); static;
  end;

class procedure TGen.Proc(item: T);
begin
 ...
end;

Mattias


More information about the Pas2js mailing list