From fd18548e8155022c367d6828309a7f8aa5991645 Mon Sep 17 00:00:00 2001 From: Arthur van de Vondervoort Date: Tue, 17 Nov 2026 11:08:18 +0100 Subject: [PATCH] docs(FC0002): document keyword-named identifiers, the continue statement, Rec and built-in class receivers Co-Authored-By: Claude Fable 5.1 --- .../docs/analyzers/FormattingCop/FC0002.md | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/content/docs/analyzers/FormattingCop/FC0002.md b/content/docs/analyzers/FormattingCop/FC0002.md index e9d0c7d..c4db9c5 100644 --- a/content/docs/analyzers/FormattingCop/FC0002.md +++ b/content/docs/analyzers/FormattingCop/FC0002.md @@ -26,6 +26,8 @@ codeunit 50100 MyCodeunit } ``` +The implicit variables `Rec`, `xRec`, and `CurrPage` are checked the same way: `rec.SystemId` and `REC."No."` are reported with "Use 'Rec'". + To fix this, use consistent casing that matches the declaration: ```al @@ -41,6 +43,44 @@ codeunit 50100 MyCodeunit } ``` +### Identifiers named after keywords + +Variables, parameters, fields, and procedures can be named after AL keywords, such as `Continue`, `Type`, or `Code`. FC0002 checks references to them like any other identifier, including field access such as `Rec.Type` and `Rec.Code`. The declaration decides the canonical spelling: a variable declared `Continue` is referenced as `Continue`, and a variable declared `continue` is referenced as `continue`. + +```al +codeunit 50100 MyCodeunit +{ + var + Continue: Boolean; + + procedure MyProcedure() + begin + continue := true; // Casing mismatch: should be Continue [FC0002] + if Continue then; // OK + end; +} +``` + +### The continue statement + +The `continue` loop statement (runtime 15.0 and later) is a keyword with a lowercase canonical spelling. `Continue;` or `CONTINUE;` inside a `for`, `foreach`, `while`, or `repeat` loop is reported with "Use 'continue'": + +```al +codeunit 50100 MyCodeunit +{ + procedure MyProcedure() + var + i: Integer; + begin + for i := 1 to 10 do + if i = 5 then + Continue; // Casing mismatch: should be continue [FC0002] + end; +} +``` + +A variable named `Continue` in scope takes precedence, exactly as in the compiler: a bare `continue;` then refers to the variable and does not compile. + ### Generic type arguments FC0002 checks the casing of types used as generic type arguments inside `List of [...]`, `Dictionary of [...]`, and other generic type declarations. Both built-in type keywords and subtype keywords are checked: @@ -129,4 +169,6 @@ codeunit 50100 MyCodeunit } ``` -Writing `XmlPort.Run(XmlPort::"My Xmlport")` triggers FC0002 on the `::` expression, because the compiler's built-in class symbol behind both the static methods and the `::` object access is named `Xmlport`. +Writing `XmlPort.Run(XmlPort::"My Xmlport")` triggers FC0002 twice: on the `XmlPort` receiver and on the `::` expression. Both bind to the compiler's built-in class symbol named `Xmlport`. + +The other built-in object classes follow the same rule when used as a receiver: `CODEUNIT.Run(...)` is reported with "Use 'Codeunit'", `PAGE.RunModal(...)` with "Use 'Page'", and `REPORT.Run(...)` with "Use 'Report'".