Menu

#336 Formatter does not handle inline variables in try..finally/except

Closed
closed-fixed
None
5
2023-11-26
2023-11-26
No

Inline variable declarations like this

 try
   var a := 2;
   test(a);
finally
end;

are formatted as

 try
var a:=2;
   test(a);
finally
end; 

The variable declaration should be indented to the same level as the code.

Adding 2 lines in 'GX_CodeFormatterFormatter.pas' at line 1633 fixes this problem:

        end else if (FPrevToken.GetExpression(exp) and SameText(exp, 'for')) then begin
           // for with inline var declaration
         end else if (fStack.GetTopType = rtTry) then begin
           // inline var declaration inside Try/finally block
         end else begin

Report and patch from Miko330 in Delphi Praxis:
https://en.delphipraxis.net/topic/10565-problem-indent-with-inline-var-inside-tryfinally/

Discussion

  • Thomas Mueller

    Thomas Mueller - 2023-11-26
    • status: open --> closed-fixed
    • Group: New --> Closed
     
  • Thomas Mueller

    Thomas Mueller - 2023-11-26

    Modified patch applied and verified to fix the problem in revision #4109

    Also added to formatter unit tests testfile_InlineVarInTryFinally1.pas, testfile_InlineVarInTryFinally2.pas and testfile_InlineVarInTryFinally3.pas in revision #4108

     

Log in to post a comment.

MongoDB Logo MongoDB