Skip to content

fix: PC0037 CodeFix no longer fabricates semicolon before else#399

Merged
Arthurvdv merged 1 commit into
mainfrom
fix/pc0037-codefix-semicolon-before-else
Jul 11, 2026
Merged

fix: PC0037 CodeFix no longer fabricates semicolon before else#399
Arthurvdv merged 1 commit into
mainfrom
fix/pc0037-codefix-semicolon-before-else

Conversation

@Arthurvdv

Copy link
Copy Markdown
Member

Problem

The PC0037 (UseValidateForFieldAssignment) CodeFix always fabricated a SemicolonToken when rewriting Rec.Field := Value into Rec.Validate(Field, Value). AL forbids a semicolon on a statement directly before else, so applying the fix to a then-branch assignment produced non-compiling code:

if BankImpExpMgtSAK.IsIBAN(IBANOrDesription) then
    Bankstatementline.Validate(IBAN, ...);  // <- illegal semicolon
else begin
end;

Although #395 was reported against the workspace Fix All, the semicolon was fabricated unconditionally, so single-instance fixes broke too.

Fix

Reuse the original assignment.SemicolonToken (a missing token when the assignment has none) instead of constructing a fresh one. Same pattern already used in GlobalLanguageImplementTranslationHelper.cs.

Tests

Two new HasFix regression cases (verified to fail against the unfixed CodeFix):

  • IfElseNoSemicolon — issue repro: assignment as then-branch of if ... then ... else begin end;
  • NestedIfElseInRepeatUntil — then-branch assignment before else inside repeat ... until

Full PlatformCop suite: 476/476 passing.

Follow-up

#398 tracks auditing the other CodeFixes that fabricate semicolon tokens.

Fixes #395

The CodeFix always constructed a SemicolonToken when rewriting a field
assignment to Validate(). AL forbids a semicolon on a statement directly
before 'else', so fixing a then-branch assignment produced non-compiling
code. Reuse the original assignment's SemicolonToken instead (a missing
token when absent).

Adds HasFix regression fixtures: IfElseNoSemicolon (issue repro) and
NestedIfElseInRepeatUntil.

Fixes #395

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Arthurvdv
Arthurvdv merged commit 60fd07f into main Jul 11, 2026
50 checks passed
@Arthurvdv
Arthurvdv deleted the fix/pc0037-codefix-semicolon-before-else branch July 11, 2026 15:33
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.

[Bug] PC0037 - CodeFix for workspace generate semicolon for non semicolon lines

1 participant