Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2014-02

overload and Error: Duplicate identifier "Foo"

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Martin Frb
project1.lpr(5,19) Error: Duplicate identifier "Foo"

Now the interesting part is that ONLY happens if the two procedures are part of a class AND the parmeter has the same name as the procedure.

If I declare 2 procedures like that outside a class, then there is no error. Also there is no error, if it is just one procedure in a class.

It also happens like that
     procedure aFoo(Foo:pointer);
     procedure bFoo(aFoo, Bar:pointer);

So that shows why there is a conflict, and what conflicts with what "bfoo" is already used in the class. Now that is correct.

But if fpc checks (correctly) that a param name has not yet been used in the current context (class), then why does it not detect

     procedure aFoo(aFoo:pointer);

the param aFoo should conflict with the procedure? It is also in the same context ?

Is this exception (from being checked) intentional?

------
program project1;
type
   TSome = class
     procedure Foo(Foo:pointer); overload;
     procedure Foo(Foo, Bar:pointer); overload;
   end;
{ TSome }
procedure TSome.Foo(Foo: pointer);
begin end;
procedure TSome.Foo(Foo, Bar: pointer);
begin end;
begin
end.

Reply by email

Sven Barth
to Martin Frb
Martin Frb wrote 25 lines
project1.lpr(5,19) Error: Duplicate identifier "Foo" Now the interesting part is that ONLY happens if the two procedures are part of a class AND the parmeter has the same name as the procedure. If I declare 2 procedures like that outside a class, then there is no error. Also there is no error, if it is just one procedure in a class. It also happens like that procedure aFoo(Foo:pointer); procedure bFoo(aFoo, Bar:pointer); So that shows why there is a conflict, and what conflicts with what "bfoo" is already used in the class. Now that is correct. But if fpc checks (correctly) that a param name has not yet been used in the current context (class), then why does it not detect procedure aFoo(aFoo:pointer); the param aFoo should conflict with the procedure? It is also in the same context ? Is this exception (from being checked) intentional?

The checks against duplicate identifiers are sadly not as strict as one might wish... :( (especially since the introduction of nested types) What you encountered here is just another example.

Regards,
Sven

Reply by email