View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0038076 | pas2js | transpiler | public | 2020-11-13 15:59 | 2020-12-29 03:40 |
Reporter | Sven Barth | Assigned To | Mattias Gaertner | ||
Priority | normal | Severity | minor | Reproducibility | always |
Status | resolved | Resolution | fixed | ||
Product Version | trunk | ||||
Summary | 0038076: Hint about local variable being assigned, but not used for record field | ||||
Description | If I have a record type and don't explicitly read from a field somewhere , but do write to it, then the transpiler will bring the hint "Hint: Local variable "xxx" is assigned but never used". | ||||
Steps To Reproduce | Compile attached example. | ||||
Tags | No tags attached. | ||||
Fixed in Revision | |||||
Attached Files |
|
|
trectype.pp (203 bytes)
program trectype; type TTest = record f1: Integer; f2: Integer; end; function Test: TTest; begin Result.f1 := 42; Result.f2 := 21; end; begin Writeln(Test.f1); end. |
|
In this particular example the hint is correct. The f2 is never read. |
|
OTOH when passing the record to an untyped or jsvalue value, then the analyzer should mark all fields as used. Maybe you mean this case? |
|
For what it's worth FPC or Delphi do not complain if a field of a record isn't used, only if the whole variable isn't used in any way. After all I might use a record from some unit where I'm only interested in some fields, but the routine to populate the record fills all anyway. For example imagine this: === code begin === uses Types, SomeUnit; var s: TSize; begin s := GetScreenSize; // from SomeUnit if s.cx < 1024 then Writeln('You poor soul') else Writeln('Your screen is wide enough'); end. === code end === Should there really be a hint about TSize.cy being assigned, but unused when I'm not interested in it at all? |
|
The argument of "I'm only interested..all anyway" is applicable to all such hints, not only record fields. About Delphi/fpc compatibility: pas2js differ here from Delphi/FPC, as records are not continuous blocks of memory, and pas2js can omit fields. Maybe there can be a separate msg number for record fields, so users can disable this particular type of half used field. |
|
There now separate hints: 4501 field "x" not used 4502 field "x" assigned but never used |
Date Modified | Username | Field | Change |
---|---|---|---|
2020-11-13 15:59 | Sven Barth | New Issue | |
2020-11-13 15:59 | Sven Barth | File Added: trectype.pp | |
2020-11-28 11:47 | Mattias Gaertner | Assigned To | => Mattias Gaertner |
2020-11-28 11:47 | Mattias Gaertner | Status | new => assigned |
2020-11-28 11:51 | Mattias Gaertner | Note Added: 0127233 | |
2020-11-28 11:52 | Mattias Gaertner | Status | assigned => feedback |
2020-11-28 11:52 | Mattias Gaertner | Note Added: 0127234 | |
2020-11-28 16:00 | Sven Barth | Note Added: 0127239 | |
2020-11-28 16:00 | Sven Barth | Status | feedback => assigned |
2020-11-28 16:34 | Mattias Gaertner | Note Added: 0127241 | |
2020-12-29 03:40 | Mattias Gaertner | Status | assigned => resolved |
2020-12-29 03:40 | Mattias Gaertner | Resolution | open => fixed |
2020-12-29 03:40 | Mattias Gaertner | Note Added: 0127886 |