Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion content/docs/analyzers/FormattingCop/FC0002.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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'".
Loading