[fpc-devel] Local variable names and colision with attributes/properties names

michael.vancanneyt at wisa.be michael.vancanneyt at wisa.be
Thu Sep 27 16:30:17 CEST 2012



On Thu, 27 Sep 2012, Marcos Douglas wrote:

> On Thu, Sep 27, 2012 at 11:01 AM, Jonas Maebe <jonas.maebe at elis.ugent.be> wrote:
>>
>> On 27 Sep 2012, at 15:51, Marcos Douglas wrote:
>>
>> What is the advantages to the compiler return the error bellow?
>> ERROR: unit1.pas(31,3) Error: Duplicate identifier "FooVar"
>>
>> Why the compiler do not respect the scope, ie, the local variable
>> should have the preference, I'm not right?
>>
>>
>> Yes, but the human brain is very good at confusing such things, and it's
>> very easy to accidentally assign something to a local variable instead of to
>> a field.
>
> Only Pascal uses that way?

No, the brain works that way.

The FPC team decided to protect you from accidental mistakes by forbidding
this special case in $mode objfpc.

For me, it has become second nature never ever to have a variable with the
same name as a property, even in Delphi.

Michael.



More information about the fpc-devel mailing list