View Issue Details

IDProjectCategoryView StatusLast Update
0037934FPCCompilerpublic2020-10-16 23:30
ReporterMStoll86 Assigned ToMichael Van Canneyt  
Status resolvedResolutionno change required 
Product Version3.0.4 
Summary0037934: Compiler error "duplicate identifier" for parameters of static method of advanced record
DescriptionI work in mode objfpc with the mode switch advancedrecords. When I now create a record like the following,

TMyRecord = record
  a : integer;
  class function Create(a : integer) : TMyRecord; static;

class function TMyRecord.Create(a : integer) : TMyRecord;
  result.a := a;

the compiler says that "a" is a duplicate identifier. I understand this error in cases where the method is NOT a CLASS method, since both the parameter of the method and the field of the class are within the scope of that method

In the class-method-case, however, there should not be an error, since there can not be any confusion about "a". The body of the class method "Create" can not access the field "a" but only the parameter "a" in any case.

I can suppress that behavior by using {$modeswitch duplicatelocals}. As said, however, parameter of class methods and normal fields (i.e. non-static / non-class variables) should not interfere anyway.
TagsNo tags attached.
Fixed in Revision
Attached Files


Michael Van Canneyt

2020-10-16 23:30

administrator   ~0126357

This is as designed, if you use objfpc mode then the compiler will refuse this, because it *can* lead to confusion.
That some cases where the confusion is less likely will also be stopped is normal and will not be changed.
You can simply rename the a in your class method.

Issue History

Date Modified Username Field Change
2020-10-16 22:37 MStoll86 New Issue
2020-10-16 23:30 Michael Van Canneyt Assigned To => Michael Van Canneyt
2020-10-16 23:30 Michael Van Canneyt Status new => resolved
2020-10-16 23:30 Michael Van Canneyt Resolution open => no change required
2020-10-16 23:30 Michael Van Canneyt FPCTarget => -
2020-10-16 23:30 Michael Van Canneyt Note Added: 0126357