Преглед изворни кода

* handle fields with the same name as a type also correctly in case of
nested records (mantis #15592)

git-svn-id: trunk@14910 -

Jonas Maebe пре 15 година
родитељ
комит
674cdaf3fc
3 измењених фајлова са 42 додато и 6 уклоњено
  1. 1 0
      .gitattributes
  2. 24 6
      compiler/pdecvar.pas
  3. 17 0
      tests/webtbs/tw15592.pp

+ 1 - 0
.gitattributes

@@ -10277,6 +10277,7 @@ tests/webtbs/tw15467.pp svneol=native#text/pascal
 tests/webtbs/tw15500.pp svneol=native#text/plain
 tests/webtbs/tw15504.pp svneol=native#text/plain
 tests/webtbs/tw15530.pp svneol=native#text/pascal
+tests/webtbs/tw15592.pp svneol=native#text/plain
 tests/webtbs/tw15607.pp svneol=native#text/plain
 tests/webtbs/tw15619.pp svneol=native#text/plain
 tests/webtbs/tw15668.pp svneol=native#text/pascal

+ 24 - 6
compiler/pdecvar.pas

@@ -1365,6 +1365,7 @@ implementation
          srsymtable : TSymtable;
          visibility : tvisibility;
          recst : tabstractrecordsymtable;
+         recstlist : tfpobjectlist;
          unionsymtable : trecordsymtable;
          offset : longint;
          uniondef : trecorddef;
@@ -1388,6 +1389,7 @@ implementation
           consume(_ID);
          { read vars }
          sc:=TFPObjectList.create(false);
+         recstlist:=TFPObjectList.create(false);;
          while (token=_ID) and
             not((vd_object in options) and
                 (idtoken in [_PUBLIC,_PRIVATE,_PUBLISHED,_PROTECTED,_STRICT])) do
@@ -1407,14 +1409,29 @@ implementation
              until not try_to_consume(_COMMA);
              consume(_COLON);
 
-             { Don't search in the recordsymtable for types }
+             { Don't search in the recordsymtable for types (can be nested!) }
+             recstlist.count:=0;
              if ([df_generic,df_specialization]*tdef(recst.defowner).defoptions=[]) and
-                not is_class(tdef(recst.defowner)) then
-               symtablestack.pop(recst);
+                 not is_class(tdef(recst.defowner)) then
+               begin
+                 recstlist.add(recst);
+                 symtablestack.pop(recst);
+                 while (is_object(tdef(symtablestack.top.defowner)) or
+                        (symtablestack.top.symtabletype=recordsymtable)) and
+                       ([df_generic,df_specialization]*tdef(symtablestack.top.defowner).defoptions=[]) do
+                   begin
+                     recst:=tabstractrecordsymtable(symtablestack.top);
+                     recstlist.add(recst);
+                     symtablestack.pop(recst);
+                   end;
+               end;
              read_anon_type(hdef,false);
-             if ([df_generic,df_specialization]*tdef(recst.defowner).defoptions=[]) and
-                not is_class(tdef(recst.defowner)) then
-               symtablestack.push(recst);
+             { restore stack }
+             for i:=recstlist.count-1 downto 0 do
+               begin
+                 recst:=tabstractrecordsymtable(recstlist[i]);
+                 symtablestack.push(recst);
+               end;
 
              { Process procvar directives }
              if maybe_parse_proc_directives(hdef) then
@@ -1547,6 +1564,7 @@ implementation
                    recst.addfield(fieldvs,visibility);
                end;
            end;
+          recstlist.free;
 
          { Check for Case }
          if (vd_record in options) and

+ 17 - 0
tests/webtbs/tw15592.pp

@@ -0,0 +1,17 @@
+{ %norun }
+
+program project1;
+TYPE
+  TRTime = Record
+    rtDay : Integer;
+  end;
+  TTimeRange = Record
+    trFlags : Integer;
+    trTime : TRTime;
+    case trType : Integer of
+     0 : (trTime2 : TRTime);
+     1 : (trMinutes : Integer);
+  end;
+
+begin
+end.