View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0037934 | FPC | Compiler | public | 2020-10-16 22:37 | 2020-10-16 23:30 |
Reporter | MStoll86 | Assigned To | Michael Van Canneyt | ||
Priority | normal | Severity | minor | Reproducibility | always |
Status | resolved | Resolution | no change required | ||
Product Version | 3.0.4 | ||||
Summary | 0037934: Compiler error "duplicate identifier" for parameters of static method of advanced record | ||||
Description | I 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; end; class function TMyRecord.Create(a : integer) : TMyRecord; begin result.a := a; end; 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. | ||||
Tags | No tags attached. | ||||
Fixed in Revision | |||||
FPCOldBugId | |||||
FPCTarget | - | ||||
Attached Files |
|
|
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. |
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 |