[fpc-pascal] Re: Duplicate Identifier

Sven Barth pascaldragon at googlemail.com
Fri Mar 2 21:14:09 CET 2012


On 02.03.2012 20:03, Sven Barth wrote:
>  > One more question: why this feature isn't works when used with arguments?
>  > The arguments could have the same name of a property.
>
> Normally it should work with arguments as well, but there is a bug if
> you define a property with an identifier that's used in a method that
> was defined before the property. In that latter case the check does not
> work.

To illustrate this a bit:

=== source begin ===

program dupidenttest;

{$mode objfpc}

type
   TTest1 = class
     fFoo: LongInt;
     property Foo: LongInt read fFoo;
     procedure Bar(Foo: LongInt);
   end;

   TTest2 = class
     fFoo: LongInt;
     procedure Bar(Foo: LongInt);
     property Foo: LongInt read fFoo;
   end;

procedure TTest1.Bar(Foo: LongInt);
begin

end;

procedure TTest2.Bar(Foo: LongInt);
begin

end;

begin

end.

=== source end ===

results in the following compiler output:

=== output begin ===

Free Pascal Compiler version 2.6.0 [2011/12/23] for i386
Copyright (c) 1993-2011 by Florian Klaempfl and others
Target OS: Linux for i386
Compiling dupidenttest.pas
dupidenttest.pas(9,19) Error: Duplicate identifier "Foo"
dupidenttest.pas(31) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
Error: /mnt/data/applications/fpc/2.6.0/bin/ppc386 returned an error 
exitcode (normal if you did not specify a source file to be compiled)

=== output end ===

If I comment out TTest1 then the program compiles successfully.

Regards,
Sven



More information about the fpc-pascal mailing list