From 69fb67dba2192620444a07998ee47cf038bd3328 Mon Sep 17 00:00:00 2001 From: TetzkatLipHoka Date: Sat, 11 Jul 2026 16:28:25 +0200 Subject: [PATCH] Accept Delphi's 'packed' keyword in type declarations (fixes #246) The parser rejected 'packed record', 'packed array' and 'packed set' in script type sections and AddTypeS declarations, although PascalScript records and arrays are always packed anyway - Delphi type declarations could not be pasted into scripts unchanged. ReadType now skips a leading 'packed' when a structured type (record/array/set) follows; anything else after 'packed' is still an error, and the memory layout is unaffected. Repro (fails on master, passes with this change, DCC32+DCC64): type TP = packed record x, y: Integer; end; // script type section Sender.AddTypeS('THostPacked', 'packed record a: Byte; b: Integer; end'); Co-Authored-By: Claude Fable 5 --- Source/uPSCompiler.pas | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Source/uPSCompiler.pas b/Source/uPSCompiler.pas index f13307e2..42a8c908 100644 --- a/Source/uPSCompiler.pas +++ b/Source/uPSCompiler.pas @@ -4053,6 +4053,19 @@ function TPSPascalCompiler.ReadType(const Name: tbtString; FParser: TPSPascalPar Intf: TPSInterface; {$ENDIF} begin + { issue #246: accept Delphi's 'packed' before structured type declarations. + PascalScript records/arrays are always packed, so it only affects parsing } + if (FParser.CurrTokenID = CSTI_Identifier) and (FParser.GetToken = 'PACKED') then + begin + FParser.Next; + if not ((FParser.CurrTokenId = CSTII_Record) or (FParser.CurrTokenId = CSTII_Array) or + (FParser.CurrTokenId = CSTII_Set)) then + begin + MakeError('', ecIdentifierExpected, ''); + Result := nil; + Exit; + end; + end; if (FParser.CurrTokenID = CSTII_Function) or (FParser.CurrTokenID = CSTII_Procedure) then begin Result := ReadTypeAddProcedure(Name, FParser);