Repository navigation
fix(PC0031): reset partial state after a hand-off that can change it - #694
Merged
Merged
Conversation
A tracked local passed by var to a procedure or event publisher, handed to a built-in such as Clear, Codeunit.Run or Page.Run, or used as the receiver of a table procedure can be reset by the callee (SetLoadFields(), Reset, a full read), so a full-field operation after the hand-off is no longer reported. By-value arguments do not reset: the callee works on a copy with its own load selection. Findings made before a reset are committed first, so a var publisher raised after the write (or a later Clear) no longer erases the report. The rule doc records why globals, parameters, cross-procedure flows and event subscribers stay deliberate non-reports. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Charging every load-fields location with the variable's whole write set reported a later SetLoadFields that no write followed. Each write now charges only the locations that preceded it on the path, so a reset or hand-off cannot erase a finding and the end-of-walk merge is gone. Co-Authored-By: Claude Fable 5.1 <[email protected]>
A RecordRef assigned or passed by value refers to the same table instance, so only a by-value Record argument is exempt from the hand-off reset. Co-Authored-By: Claude Fable 5.1 <[email protected]>
… the finding Co-Authored-By: Claude Fable 5.1 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Feasibility verdict for the PC0031 roadmap in #517 (globals, parameters, cross-procedure tracing, event tracing) plus one hardening change the investigation exposed.
Verdict: none of the four items is implemented.
ReferenceMethodSymbol.DeclaringSyntaxReferenceis null).The full Investigation Report with corpus counts and examples is posted on #517; the reasons are recorded under Deliberate non-reports in the rule doc.
Hardening: PC0031 ignored hand-offs. A tracked local passed by
varto a procedure or event publisher, handed to a built-in (Clear,Codeunit.Run,Page.Run, theTransferFields/Copysource) or used as the receiver of a table procedure can be reset by the callee (SetLoadFields(),Reset, a full read), so a full-field operation after the hand-off was a latent false positive. The walker now resets the variable's partial state on such hand-offs. By-valueRecordarguments do not reset: the callee works on a copy with its own load selection (Microsoft Learn, Using partial records, "Iterating over records"). A by-valueRecordRefdoes reset, because it refers to the same table instance (Microsoft Learn, RecordRef data type).Findings are now recorded at the write, per load-fields location: each
SetLoadFieldsis charged only with the JIT-load writes that followed it on the path. SoDelete(); OnAfterDelete(MyTable)(avarpublisher after the write) andDelete(); Clear(MyTable)keep their report (the latter was a false negative before), and aSetLoadFieldsthat no write follows is never reported (SetLoadFields(A); Get; Delete; SetLoadFields(B); Get;reported B before). The end-of-walk merge of write sets is gone.Fixtures
NoDiagnostic (red before the change):
VarPassedBetweenPartialReadAndWrite,TableProcedureBetweenPartialReadAndWrite,PassedToCodeunitRunBetweenPartialReadAndWrite,EventPublisherBetweenPartialReadAndWrite,NamespacedVarPassedBetweenPartialReadAndWrite,FirstSetLoadFieldsBeforeHandOff,SecondSetLoadFieldsAfterHandOffWithoutWrite,SecondSetLoadFieldsAfterWriteWithoutWrite,RecordRefByValuePassedBetweenPartialReadAndWrite,PassedToGetTableBetweenPartialReadAndWrite.HasDiagnostic:
ByValuePassedBetweenPartialReadAndWrite,VarPassedAfterWrite,NewSetLoadFieldsAfterHandOff,VarPassedInBranchBetweenPartialReadAndWrite(green before),ClearAfterWrite(red before),ResetAfterWrite,SetLoadFieldsNoArgsAfterWrite.Verification
dotnet testPartialRecordsCauseJitLoad: 49 passed; UsePartialRecordsForLoops: 153 passeddotnet build ALCops.sln,dotnet format --verify-no-changes: cleanContinuousIntegrationBuild=true(netstandard2.1, net8.0, net10.0): 0 warningsValidate-Rules.ps1: OKCompanion docs PR: ALCops/alcops.dev#245
Closes #517
🤖 Generated with Claude Code