[fpc-pascal] Two possible generics bugs

Sven Barth pascaldragon at googlemail.com
Fri Nov 29 08:00:12 CET 2019


Ryan Joseph via fpc-pascal <fpc-pascal at lists.freepascal.org> schrieb am
Fr., 29. Nov. 2019, 01:11:

>
>
> > On Nov 28, 2019, at 6:38 PM, Sven Barth via fpc-pascal <
> fpc-pascal at lists.freepascal.org> wrote:
> >
> > TFPGObjectList has a constraint to class types, so you need to constrain
> your T as well using ": class".
> >
> > Please note however that you'll likely encounter another bug then once
> you move your function to a unit:
> https://bugs.freepascal.org/view.php?id=35943
>
> A better error would be nice but I guess I can't do this anyways until the
> other bug is fixed.
>

Why? It does say that a class type is expected. And the column of the error
should point to the correct location.
That's the same error you'd get when specializing outside of a generic with
a non-class type.


>
> > The "specialize" is part of the generic identifier, so it must be
> "FGL.specialize TFPGObjectList<T>".
> >
> > That said however an internal error should not happen (especially the
> one I just added some days ago ^^'). Please report this one.
> >
>
> That doesn't look right to my eyes but ok. I filed a report (
> https://bugs.freepascal.org/view.php?id=36377).
>

The idea is that "specialize" belongs to the identifier just like "generic"
does. This comes especially apparent for nested specializations:

SomeUnit.specialize SomeType<... >.specialize SomeFunc<... >


>
> It looks like my plan was foiled so I made a non-generic attempt. Can you
> explain why I get the EListError at runtime? I checked the itemSize
> property and it's the same for both lists.
>
> {$mode objfpc}
>
> program test;
> uses
>   FGL;
>
> type
>   TNode = class (TInterfacedObject)
>   end;
>   TNodeObjectList = specialize TFPGInterfacedObjectList<TNode>;
>
> function CopyList (source: TFPSList): TFPSList;
> begin
>   result := TFPSList(source.ClassType.Create);
>   result.Assign(source);
> end;
>
> var
>   a, b: TNodeObjectList;
> begin
>   a := TNodeObjectList.Create;
>   // EListError: Incompatible item size in source list
>   b := CopyList(a) as TNodeObjectList;
> end.
>

Can't tell right now from looking at it. Will need to test that later on.

Regards,
Sven

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20191129/80b89288/attachment.html>


More information about the fpc-pascal mailing list