[Lazarus] Code formatter

Michael Van Canneyt michael at freepascal.org
Sat Oct 19 18:11:03 CEST 2024


Hi,

I've been playing with the code formatter.

If the 'Fix spacing' is checked, and 'Spaces around operators' is set to
'Never', the formatter nevertheless changes

lName:='';

to

lName := '';

Since the assignment operator is an operator, I expect it to leave the
statement as it was.

Is this intentional, or is it a bug ?

>From my debugging, I can say the following:

In SingleSpaceAfter it is hard-wired to have a space:

   SingleSpaceAfterTokens: TTokenTypeSet = [ttColon, ttAssign, ttComma,
     ttPlusAssign, ttMinusAssign, ttTimesAssign, ttFloatDivAssign];

   if (pt.TokenType in SingleSpaceAfterTokens) then
   begin
     lcPrev := pt.PriorSolidToken;
     if (lcPrev <> nil) and (lcPrev.TokenType = ttDot) then // operaror  typename.:=( )  .+= .*=
       exit(false);
     exit(True);
   end;

Similarly, in SingleSpaceBefore, it is hard-wired to have a space:

   if (pt.TokenType in AssignmentDirectives) then
   begin
     lcPrev := pt.PriorSolidToken;
     if (lcPrev <> nil) and (lcPrev.TokenType = ttDot) then // operaror  typename.:=( )
       exit(false);
     exit(True);
   end;

So, in my opinion, clearly a bug.

:= is an operator, and should therefor obey the setting for operators.

(or a separate setting is made for the assignment operator)

Yesterday's Lazarus.

Michael.


More information about the lazarus mailing list