bcquality/microsoft/knowledge/style/variable-name-must-not-shadow.md
Jesper Schulz-Wedde 2b5550c346
Some checks failed
Validate knowledge index / validate-index (push) Has been cancelled
Validate AL review fixtures / validate-review-fixtures (push) Has been cancelled
Validate frontmatter and structure / validate (push) Has been cancelled
Improve partner onboarding and documentation navigation (#174)
Lead with a complete plugin quick start and add task-oriented usage, troubleshooting, customization, and contribution guides. Preserve the broader plugin framing, correct conflicting contract guidance, support Agents folder reviews, and align repository validation. Convert existing sample references to clickable links without changing knowledge rules.

Co-authored-by: Jesper Schulz-Wedde <jesper.schulzwedde@microsoft.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
2026-09-09 17:31:03 +02:00

1.8 KiB

bc-version domain keywords technologies countries application-area
all
style
variable-name
shadow
conflict
aa0198
aa0202
aa0204
codecop
al
w1
all

Local variable names must not shadow globals, fields, methods, or actions (CodeCop AA0198/AA0202/AA0204)

Description

Three CodeCop rules — AA0198, AA0202, AA0204 — together forbid a local variable from sharing a name with a global variable on the same object, with a field on the same table or page source, with a procedure on the same object, or with an action on the same page. The compiler resolves the conflict by binding the closer scope, so a local Customer: Text will silently override a global Customer: Record Customer for the duration of a procedure — every call site reading Customer.Name from inside that procedure refers to the text, and the breakage is invisible to a reader who has both declarations on screen.

Best Practice

Differentiate every local declaration from globals, fields, procedures, and actions on the same object. Customer global plus CustomerName local; method GetAmount plus local SalesAmount. The standard pattern is to attach a noun suffix to the local (CustomerName, CustomerRec, CustomerNo) rather than to the global.

See sample: variable-name-must-not-shadow.good.al.

Anti Pattern

A procedure that declares a local Customer: Text inside a codeunit that already has a global Customer: Record Customer. The local wins and the global becomes unreachable inside the procedure. AA0198/AA0202/AA0204 flag this category of conflict whether the colliding entity is a global, a field, a method, or an action.

See sample: variable-name-must-not-shadow.bad.al.