Repository navigation
fix(AC0032): stop a temporary local from resolving to a same-named global - #640
Merged
Merged
Conversation
…obal Temporary records enter none of the per-method name maps, so a temporary local, parameter or named return that shadows a global record fell through to the object-scope lookup: its database calls counted as uses of the global's permission, or hit the RecordRef bailout. Locals that enter no map are now tracked in a shadow set that ends the lookup. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ct scope A local that enters no map can only mislead the lookup when an object-scope record, RecordRef or DataTransfer shares its name, so bodies without such a collision allocate no shadow set. Adds a fixture for a non-record local shadowing a global record. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem
AC0032 resolves receivers through per-method name maps built from locals, parameters and the named return value. Temporary records (and locals of any other unmapped type) enter no map, so when such a local shadows an object-scope variable of the same name, the lookup falls through to the object scope:
Record:MyTable.Modify()on the temporary local counts as a use of the global'smpermission (false negative);RecordRef: the call hits the object-scope RecordRef set and triggers the whole-object bailout, silencing every AC0032 diagnostic in that object (false negative).IsDataTransferReceiverhad the same local-shadowing hole.Fix
A per-method
localShadowNamesset (SemanticFacts.NameEqualityComparer) collects every local, parameter and named return that enters no map and whose name also exists in the object scope (record,RecordReforDataTransfer), so bodies without such a collision allocate nothing. After a local record-map miss, a name in this set ends the lookup before the object scope;IsDataTransferReceivertreats it as a local shadow too.Fixtures
HasDiagnostic/TemporaryLocalShadowsGlobalRecord:rmwith a global read and a temporary local and temporaryvarparameter callingModify();mis reported.HasDiagnostic/TemporaryLocalShadowsGlobalRecordRef: a temporary local shadowing a globalRecordRef; the entry is reported instead of bailing out.HasDiagnostic/TemporaryNamedReturnShadowsGlobalRecord: a temporary named return value shadowing a global record;mis reported.HasDiagnostic/LocalCodeunitShadowsGlobalRecord: a codeunit local (with its ownModify()) shadowing a global record;mis reported.Both failed before the fix ("There is no issue reported for AC0032").
Review notes
GetSymbolInfoeither, and the fallback rejects temporaries anyway, so binding every temporary-record call would add a body bind per call on the hottest AC0032 path for nothing.SemanticFacts.NameEqualityComparer, the house rule for AL names; the pre-existing maps keepOrdinalIgnoreCaseto keep this diff minimal. Both are case-insensitive ordinal comparisons.IsDataTransferReceivershadow check has no fixture because it changes no outcome. Without it, a non-DataTransferlocal that shadows a globalDataTransfertakes the executor path,TryGetFromDataTransferrejects the non-built-in target without bailing out, and the skippedTryGetPermissionFromDbAccesscall would have found nothing, sinceCopyRows/CopyFieldsare not inMethodOperationMap. The check only saves that body bind.DataTransfercannot fall throughTryGetPermissionFromDbAccessto a same-named global record: noDataTransfermethod is inMethodOperationMap, so the lookup returns before the receiver is resolved.else ifbranches mirror the existing per-kind chains in the same three loops (locals, parameters, named return) rather than introducing a helper.Part of #449
🤖 Generated with Claude Code