Skip to content

fix(AC0032): stop a temporary local from resolving to a same-named global - #640

Merged
Arthurvdv merged 3 commits into
mainfrom
fix/ac0032-temporary-local-shadowing
Nov 17, 2026
Merged

Arthurvdv merged 3 commits into
mainfrom
fix/ac0032-temporary-local-shadowing

Conversation

@Arthurvdv

@Arthurvdv Arthurvdv commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

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:

  • shadowing a global Record: MyTable.Modify() on the temporary local counts as a use of the global's m permission (false negative);
  • shadowing a global RecordRef: the call hits the object-scope RecordRef set and triggers the whole-object bailout, silencing every AC0032 diagnostic in that object (false negative).

IsDataTransferReceiver had the same local-shadowing hole.

Fix

A per-method localShadowNames set (SemanticFacts.NameEqualityComparer) collects every local, parameter and named return that enters no map and whose name also exists in the object scope (record, RecordRef or DataTransfer), 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; IsDataTransferReceiver treats it as a local shadow too.

Fixtures

  • HasDiagnostic/TemporaryLocalShadowsGlobalRecord: rm with a global read and a temporary local and temporary var parameter calling Modify(); m is reported.
  • HasDiagnostic/TemporaryLocalShadowsGlobalRecordRef: a temporary local shadowing a global RecordRef; the entry is reported instead of bailing out.
  • HasDiagnostic/TemporaryNamedReturnShadowsGlobalRecord: a temporary named return value shadowing a global record; m is reported.
  • HasDiagnostic/LocalCodeunitShadowsGlobalRecord: a codeunit local (with its own Modify()) shadowing a global record; m is reported.

Both failed before the fix ("There is no issue reported for AC0032").

Review notes

  • The shadow set deliberately returns null rather than falling through to the bound fallback. A local whose declared type is not a resolvable record cannot bind to a database record through GetSymbolInfo either, 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.
  • The set uses SemanticFacts.NameEqualityComparer, the house rule for AL names; the pre-existing maps keep OrdinalIgnoreCase to keep this diff minimal. Both are case-insensitive ordinal comparisons.
  • The IsDataTransferReceiver shadow check has no fixture because it changes no outcome. Without it, a non-DataTransfer local that shadows a global DataTransfer takes the executor path, TryGetFromDataTransfer rejects the non-built-in target without bailing out, and the skipped TryGetPermissionFromDbAccess call would have found nothing, since CopyRows/CopyFields are not in MethodOperationMap. The check only saves that body bind.
  • A local DataTransfer cannot fall through TryGetPermissionFromDbAccess to a same-named global record: no DataTransfer method is in MethodOperationMap, so the lookup returns before the receiver is resolved.
  • The three identical else if branches 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

Arthurvdv and others added 3 commits November 17, 2026 15:42
…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>
@Arthurvdv
Arthurvdv merged commit 3949ebb into main Nov 17, 2026
53 checks passed
@Arthurvdv
Arthurvdv deleted the fix/ac0032-temporary-local-shadowing branch November 17, 2026 15:25
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.

1 participant