[fpc-devel] Allow record helper inheritance in Delphi mode

Sven Barth pascaldragon at googlemail.com
Fri Sep 1 22:09:47 CEST 2017


Am 01.09.2017 21:07 schrieb "Ondrej Pokorny" <lazarus at kluug.net>:
>
> On 01.09.2017 18:38, Sven Barth via fpc-devel wrote:
>>
>> What if I do the initial specialization in a unit that does not know
about the helper? It can't just do speculative specialization once both the
specialized generic and the generic helper are used in the same unit. And
even if the compiler would postpone it till some method of the specialized
type is called things would get polluted once multiple helpers lee type are
allowed as every one of the generic helpers in scope would need to be
specialized for overload resolution.
>>
>> So in short: no, I don't *want* this, but it's due to technical reasons.
>>
>> > I guess it's because it does not know anymore that TFoo<Integer> is in
fact a closed generic type that was constructed from the open geneneric
type TFoo<T>?
>>
>> The compiler can know rather easily that a type is a specialization, but
you need to keep in mind that helpers are also active for parent types. So
if you descend from a specialization the helpers of the generic would need
to be available as well.
>>
>
> What about explicitely specializing the generic helper?
>
>   generic TMyClass<T> = class;
>   generic TMyClassHelper<T> = class helper for TMyClass<T>;
>
> ...
>
>   TMyClassInt = specialize TMyClass<Integer>;
>   TMyClassIntHelper = specialize class helper(TMyClassHelper<Integer>)
for TMyClass<Integer>;
> - or -
>   TMyClassIntHelper = specialize class helper(TMyClassHelper<Integer>)
for TMyClassInt;
>
> In this case the compiler knows about the TMyClassIntHelper for
TMyClassInt(TMyClass<Integer>) and that it has to inherit from
TMyClassHelper<Integer>.

That is basically what I was talking about though it would be like this:

=== code begin ===

TMyClassIntHelper = specialize TMyClassHelper<LongInt>;

// somewhere else
specialize TMyClass<LongInt>.SomeHelperMethod;

=== code end ===

This would even be rather easy to implement.

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20170901/7010ca9b/attachment.html>


More information about the fpc-devel mailing list