[fpc-pascal] Correct way for partial generic specialization

Sven Barth pascaldragon at googlemail.com
Tue Apr 16 19:21:10 CEST 2013


Am 16.04.2013 16:56 schrieb "leledumbo" <leledumbo_cool at yahoo.co.id>:
>
> This code:
>
> {$mode objfpc}{$H+}
>
> type
>   generic TType1<A,B> = class end;
>   generic TType2  = specialize TType1<A,String>;
>
> begin
> end.
>
> fails:
> x.pas(5,42) Error: Identifier not found "A"
> x.pas(5,42) Error: Type identifier expected
> x.pas(5,50) Error: Illegal expression
> x.pas(7,1) Error: This type can't be a generic
>

As the compiler tells you: A is not a defined type. The compiler needs to
know the complete type before it can use any type defined in there and in
this case the full type is "TType1<A, String>" where both types must come
from outside the type.

> but this code:
>
> {$mode objfpc}{$H+}
>
> type
>   generic TType1<A,B> = class end;
>   generic TType2  = class(specialize TType1<A,String>) end;
>
> begin
> end.
>
> works. Does it have to be like the 2nd code for partial generic
> specialization?

This must only work if you write "generic TType2<A> =...". Otherwise this
is a bug.

One can argue however that the following should be valid as well (AFAIK it
is not currently):

=== example begin ===

type
  generic TType2<A> = specialize TType1<A, String>;

=== example end ===

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20130416/ec22cc33/attachment.html>


More information about the fpc-pascal mailing list