瀏覽代碼

* 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

(cherry picked from commit efd0c250dfeaa0bbffb4d61e90e6d99dd2b94b0f)

Sven Barth 3 年之前
父節點
當前提交
6279283ce1
共有 2 個文件被更改,包括 29 次插入2 次删除
  1. 8 2
      compiler/symtable.pas
  2. 21 0
      tests/webtbs/tw39310.pp

+ 8 - 2
compiler/symtable.pas

@@ -1610,6 +1610,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 }
@@ -1619,8 +1620,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
@@ -1652,7 +1653,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 - 0
tests/webtbs/tw39310.pp

@@ -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.
+