[fpc-pascal] Two possible generics bugs
Testing on 3.3.1. Are these both bugs? I wanted to ask first before filing a report. {$mode objfpc} program test; uses FGL; // No Error specializing TFPGList in parameter list... generic function CopyList(source: specialize TFPGList): specialize TFPGList; begin end; // ... but getting an error specializing TFPGObjectList in parameter list // Class type expected, but got "T" generic function CopyList(source: specialize TFPGObjectList): specialize TFPGObjectList; begin end; begin end. === {$mode objfpc} program test; uses FGL; // Type identifier expected // Internal error 2019112401 generic function CopyList(source: specialize FGL.TFPGObjectList): specialize FGL.TFPGObjectList; begin end; begin end. Regards, Ryan Joseph ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Two possible generics bugs
Ryan Joseph via fpc-pascal schrieb am Do., 28. Nov. 2019, 20:36: > Testing on 3.3.1. Are these both bugs? I wanted to ask first before filing > a report. > > {$mode objfpc} > > program test; > uses > FGL; > > // No Error specializing TFPGList in parameter list... > generic function CopyList(source: specialize TFPGList): specialize > TFPGList; > begin > end; > > // ... but getting an error specializing TFPGObjectList in parameter list > // Class type expected, but got "T" > generic function CopyList(source: specialize TFPGObjectList): > specialize TFPGObjectList; > begin > end; > > begin > end. > 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 > === > > {$mode objfpc} > > program test; > uses > FGL; > > // Type identifier expected > // Internal error 2019112401 > generic function CopyList(source: specialize FGL.TFPGObjectList): > specialize FGL.TFPGObjectList; > begin > end; > > begin > end. > The "specialize" is part of the generic identifier, so it must be "FGL.specialize TFPGObjectList". That said however an internal error should not happen (especially the one I just added some days ago ^^'). Please report this one. Regards, Sven > ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Two possible generics bugs
> On Nov 28, 2019, at 6:38 PM, Sven Barth via fpc-pascal > 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. > The "specialize" is part of the generic identifier, so it must be > "FGL.specialize TFPGObjectList". > > 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). 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; 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. Regards, Ryan Joseph ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Two possible generics bugs
Ryan Joseph via fpc-pascal schrieb am Fr., 29. Nov. 2019, 01:11: > > > > On Nov 28, 2019, at 6:38 PM, Sven Barth via fpc-pascal < > fpc-pascal@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". > > > > 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; > > 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 > ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal