fcl-passrc: fixed parsing of an empty const section in a class declaration
Problem
TPasParser.ParseMembersLocalConsts called ParseConstDecl unconditionally, so an
empty const section in a class body made the parser consume the following
visibility specifier (protected, strict private, final) as a constant name:
TFoo = class(TObject)
strict private const // empty: generator emitted nothing here
protected
FBar: Integer;
end;Same effect when the const body is cut out by IFDEFs (project defines not set during a syntax check):
strict private const
{$IFDEF SOME_DEFINE}
cA = 1;
{$ENDIF}
strict private
FB: Integer;Error raised:
Expected "=" at token "Identifier FBar" in file afile.pp at line 7 column 5Found while running the Pascal Language Server (pasls uses fcl-passrc for diagnostics) over a large workspace.
Fix
ParseMembersLocalConsts now stops before consuming a token that starts a new
member section (visibility specifier or final), leaving it for the caller —
the same check the loop already did after each parsed constant, now also
applied before the first one.
packages/fcl-passrc/src/pparser.pp: the fixpackages/fcl-passrc/tests/tcclasstype.pas: regression test
Test
TTestClassType.TestConstProtectedEndEmpty, added next to the existing
TestConstProtectedEnd (from bug report 25720).
It fails on the old code with
Expected "=" at token "Identifier I" and passes with the fix.