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

Sven Barth pascaldragon at googlemail.com
Fri Sep 1 18:38:59 CEST 2017


Am 01.09.2017 14:50 schrieb "Stefan Glienke" <sglienke at dsharp.org>:
>
> > For generics the only way to support them is that you must explicitly
specialize a generic helper type. The compiler won't do any type inference
for you.
>
> IMO this makes them rather useless. Is that a technical limitation or
just something you did not want to do?
> I don't know much about compiler internals for forgive me my naivety.
>
> If I have TFoo<T> and a TFooHelper<T> and somewhere declare a
TFoo<Integer> and use a method
> from my helper can't the compiler make sure to compile the
TFooHelper<Integer> version for it?

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.

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


More information about the fpc-devel mailing list