[fpc-pascal] Generics and Scopes

Sven Barth pascaldragon at googlemail.com
Thu Nov 10 11:42:37 CET 2016


Am 10.11.2016 04:30 schrieb "African Wild Dog" <paintedlycaon at gmail.com>:
>
> 2016-11-07 14:15 GMT-02:00 Sven Barth <pascaldragon at googlemail.com>:
>>
>> Am 07.11.2016 15:58 schrieb "African Wild Dog" <paintedlycaon at gmail.com>:
>> > It is intended to change such compiler behavior in the future? It is
incompatible with Delphi and moreover it force us to break the
encapsulation of the Generic types.
>>
>> I can't answer this without you providing an example that fails.
>
>
> Sorry for the noise. Some of my classes were bad designed. They look like
this sample (Delphi XE 6 compiles):
>
> ==== CODE BEGIN ====
>
> unit sample;
>
> {$MODE delphi}
>
> interface
>
> type
>   TGenericRecord<T> = record
>   strict private
>     Interf: IInterface;
>     type
>       TMockIntfObject<T> = record // Nested generic declaration
>       end;
>
>   public
>     FValue: T;
>     procedure SetValue(Value: T);
>   end;
>
> implementation
>
> { TGenericRecord<T> }
>
> procedure TGenericRecord<T>.SetValue(Value: T);
> begin
>   Interf := TMockIntfObject.Create;
> end;
>
> end.
>
>
> ==== END ====
>
>
>  With fpc i got the error "Fatal: Declation of generic class inside
another generic class is not allowed".

Nested generics are currently indeed not supported. They are on my ToDo
list however.

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


More information about the fpc-pascal mailing list