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

Ondrej Pokorny lazarus at kluug.net
Fri Sep 1 21:06:52 CEST 2017


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>.

Ondrej



More information about the fpc-devel mailing list