* fix for #39310 by fixing various small issues in tabstractrecordsymtable.has_single_field:

- initialize the returned def to a safe default
  - correctly reset the found symbol for each loop
  - reset the result when descending into a record
+ added test
This commit is contained in:
Sven Barth 2021-08-28 17:58:34 +02:00
parent e9b880c947
commit efd0c250df
2 changed files with 29 additions and 2 deletions

View File

@ -1633,6 +1633,7 @@ implementation
sym: tfieldvarsym;
begin
result:=false;
def:=generrordef;
{ If a record contains a union, it does not contain a "single
non-composite field" in the context of certain ABIs requiring
special treatment for such records }
@ -1642,8 +1643,8 @@ implementation
{ a record/object can contain other things than fields }
currentsymlist:=symlist;
{ recurse in arrays and records }
sym:=nil;
repeat
sym:=nil;
{ record has one field? }
for i:=0 to currentsymlist.Count-1 do
begin
@ -1674,7 +1675,12 @@ implementation
end;
{ if the array element is again a record, continue descending }
if currentdef.typ=recorddef then
currentsymlist:=trecorddef(currentdef).symtable.SymList
begin
{ the record might be empty, so reset the result until we've
really found something }
result:=false;
currentsymlist:=trecorddef(currentdef).symtable.SymList
end
else
begin
{ otherwise we found the type of the single element }

21
tests/webtbs/tw39310.pp Normal file
View File

@ -0,0 +1,21 @@
{ %NORUN }
{$MODESWITCH ADVANCEDRECORDS}
Program tw39310;
Type
Rec0 = record
end;
Rec1 = record
r:Rec0;
Procedure Proc;
end;
Procedure Rec1.Proc;
begin
end;
Begin
End.