Repository navigation
fix(PC0038): treat member initialization of named record returns as assignment - #598
Conversation
…ssignment - Fixes ALCops#596 - Count field and property assignments on the named return (Result."No." := ..., Result.ReadIsolation := ...) as initialization - Unwrap conversions around the receiver and var arguments, so temporary records passed to a non-temporary var Record parameter and Clear(Result) count - Accept Init() and Clear() as explicit initialization, even as the only statement - Add NoDiagnostic fixtures for field, property, view-state, var-argument, Init and Clear forms; pin the empty body as HasDiagnostic - Document design decisions and runtime facts in the rule doc and regression catalog
…s initialization - Unwrap conversions around var arguments, so temporary records passed to a non-temporary var Record parameter and Clear(Result) count
|
Thanks @MODUSCarstenScholling, this is a clean fix and the conversion unwrap for temporary records passed to a non-temporary 1. A field of the return used as a procedure Build(Txt: Text) Result: Record MyTable
begin
Evaluate(Result."Entry No.", Txt); // var argument is Result."Entry No."
end;
procedure Build2() Result: Record MyTable
var
OutS: OutStream;
begin
Result.Blob.CreateOutStream(OutS); // receiver is Result.Blob
end;Following the same reasoning as the PR (a field is part of the returned instance), reusing the field-of-return check for the receiver and the 2.
3. Fixtures and code that the change doesn't exercise Nits
|
- Fixes ALCops#596 - Reuse return-field matching for receivers and var arguments - Add regression guards and remove unneeded receiver unwrapping - Align rule documentation and regression catalog
|
Wow, you were fast 🤯 and the last commit this covers everything from the review it seems. LGTM, so let's merge! |
Because the force is with him! And the test framework 😄 |
Summary
PC0038 reported named
Recordreturn values withoutexit(...)as "not all code paths return a value", although the procedure had initialized the return variable through its fields. For records the named form is the idiomatic one:exit(LocalRecord)is a record assignment that drops filters, the current key and the rows of a temporary table.Fixes #596
Changes
Result."No." := No;) counts as assignment.vararguments are unwrapped before matching the named return. This covers a temporary record passed to a non-temporaryvar Recordparameter, andClear(Result).Init()andClear()count as explicit initialization, even as the only statement. An empty body is still reported.Tests
NoDiagnosticfixtures:Clear()(alone and followed by a field assignment), and the non-temporaryvarargument.ReadIsolation,Init(), the temporaryvarargument, and field assignment followed byInsert().HasDiagnosticfixture: empty body.netstandard2.1,net8.0andnet10.0succeeds;dotnet formatis clean.Docs: ALCops/alcops.dev (PR #215).