Skip to content

fix(PC0038): treat member initialization of named record returns as assignment - #598

Open
MODUSCarstenScholling wants to merge 2 commits into
ALCops:mainfrom
MODUSCarstenScholling:dev-cs-issue596-pc0038-falsepos
Open

MODUSCarstenScholling wants to merge 2 commits into
ALCops:mainfrom
MODUSCarstenScholling:dev-cs-issue596-pc0038-falsepos

Conversation

@MODUSCarstenScholling

@MODUSCarstenScholling MODUSCarstenScholling commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

PC0038 reported named Record return values without exit(...) 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

  • Assigning a field of the named return (Result."No." := No;) counts as assignment.
  • Conversions around var arguments are unwrapped before matching the named return. This covers a temporary record passed to a non-temporary var Record parameter, and Clear(Result).
  • Init() and Clear() count as explicit initialization, even as the only statement. An empty body is still reported.
  • Rule doc and regression catalog: new design decisions, plus runtime facts verified on BC 29.

Tests

  • New NoDiagnostic fixtures:
    • Only these fail without the fix: field assignments (including in both branches), Clear() (alone and followed by a field assignment), and the non-temporary var argument.
    • The others pass without the fix and guard against regressions: view-state calls, ReadIsolation, Init(), the temporary var argument, and field assignment followed by Insert().
  • New HasDiagnostic fixture: empty body.
  • All PlatformCop tests pass; build for netstandard2.1, net8.0 and net10.0 succeeds; dotnet format is clean.

Docs: ALCops/alcops.dev (PR #215).

…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Rule PC0038 throws warning on named record return variables

1 participant