[fpc-devel] Generics, TObject Descendant?

Den cyraid at gmail.com
Fri Feb 20 23:03:25 CET 2015


Ahh, thanks Sven! I'll see if I can post a bug report soon of it.. I'll 
use the work-around for now. :)

On 2015-02-19 12:22 AM, Sven Barth wrote:
> On 18.02.2015 20:51, Den wrote:
>> Hi there,
>>
>> Currently this code:
>>
>>    TSomeObject<T> = Class;
>>    TSomeOtherObject<T : TObject> = Class(TSomeObject<T> );
>>
>> And finally:
>>
>>    TMyObject = Class;
>>    TSomeOtherOtherObject<T : TMyObject> = Class(TSomeOtherObject<T> );
>>
>> Comes up with error 'got "T" expected "TObject"' .. But TMyObject is
>> based off of TObject?
>
> At seems that there are still problems if TMyObject is merely a 
> forward declaration... the following works:
>
> === code begin ===
>
> type
>   TSomeObject<T> = Class
>   end;
>
>   TSomeOtherObject<T : TObject> = Class(TSomeObject<T> );
>
>   TMyObject = Class
>   end;
>
>   TSomeOtherOtherObject<T : TMyObject> = Class(TSomeOtherObject<T> );
>
> === code end ===
>
> Note 1: this is a forward declaration "XYZ = class;", this is not: 
> "XYZ = class(TObject);"
> Note2 : a generic /must not/ be a forward declaration (in this case 
> TSomeObject<T>).
>
> A forward declaration of TMyObject should be valid in this case 
> however, so please report a bug with an example program attached.
>
> Regards,
> Sven
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel




More information about the fpc-devel mailing list