Duplicate identifier in derived generic (was: Re: [fpc-pascal] (no subject))

Sven Barth pascaldragon at googlemail.com
Thu Nov 24 17:06:16 CET 2011


Am 24.11.2011 16:56, schrieb Juha Manninen:
> It says:
>   unit1.pas(40,24) Error: Duplicate identifier "FreeObjects"
>
> Why? If I change "FreeObjects" to "aFreeObjects" then it works. Again why?

You simply picked a bad example, because "TFPGObjectList" contains a 
property called "FreeObjects", thus mode ObjFPC will not allow you to 
declare a similar identifier again in this class.

Though it's inconsistent (and in my opinion a bug) that the duplicated 
declaration inside "TFPGObjectList" itself is not detected...

Note: if the property in "TFPGObjectList" would be moved before the 
constructor it should be detected as duplicate.

> Is it even ok to derive classes from specialized classes like that?

Of course it is. In Delphi (and my generics branch) even the following 
is allowed:

{$mode delphi}

type
   TSomeDerivedList<T> = class(TFPGObjectList<T>)
     // ...
   end;

Regards,
Sven



More information about the fpc-pascal mailing list