[Pas2js] Testing generics

Mattias Gaertner nc-gaertnma at netcologne.de
Tue Oct 22 14:18:37 CEST 2019


On Mon, 21 Oct 2019 19:22:33 -0700 (MST)
warleyalex via Pas2js <pas2js at lists.freepascal.org> wrote:

> generic function Min<T>(const A, B: T): T;
> begin
>   if A < B then
>     Result := A else
>     Result := B;
> end;
> 
> begin
> // it compiles/worked as expected
>   specialize Min<Integer>(1, 0);     // Min (1, 0):  0
>   specialize Min<Single>(3.14, 5);  //Min (3.14, 5):  3.14
>   specialize Min<string>('a', 'b');     //Min ("a", "b"):  a
> 
> (* but we can not compile the following: *) 
> 
>   WriteLn('Min (1, 0): ', specialize Min<Integer>(1, 0));
>   WriteLn('Min (3.14, 5): ', specialize Min<Single>(3.14, 5));
>   WriteLn('Min (''a'', ''b''): ', specialize Min<string>('a', 'b'));
> end;
> 
> projGenericsA.lpr(29,41) Error: not yet implemented:
> TInlineSpecializeExpr:TInlineSpecializeExpr [20170306102158]

Fixed.

Mattias


More information about the Pas2js mailing list