Browse Source

* fixed crash when trying to index a record without a default property

git-svn-id: trunk@17480 -
Jonas Maebe 14 years ago
parent
commit
b0e83a06af
4 changed files with 22 additions and 4 deletions
  1. 1 0
      .gitattributes
  2. 1 1
      compiler/pexpr.pas
  3. 6 3
      compiler/symtable.pas
  4. 14 0
      tests/tbf/tb0221.pp

+ 1 - 0
.gitattributes

@@ -8390,6 +8390,7 @@ tests/tbf/tb0217.pp svneol=native#text/plain
 tests/tbf/tb0218.pp svneol=native#text/plain
 tests/tbf/tb0219.pp svneol=native#text/pascal
 tests/tbf/tb0220.pp svneol=native#text/plain
+tests/tbf/tb0221.pp svneol=native#text/plain
 tests/tbf/ub0115.pp svneol=native#text/plain
 tests/tbf/ub0149.pp svneol=native#text/plain
 tests/tbf/ub0158a.pp svneol=native#text/plain

+ 1 - 1
compiler/pexpr.pas

@@ -1930,7 +1930,7 @@ implementation
                       is_dispinterface(p1.resultdef) or is_record(p1.resultdef) then
                       begin
                         { default property }
-                        protsym:=search_default_property(tobjectdef(p1.resultdef));
+                        protsym:=search_default_property(tabstractrecorddef(p1.resultdef));
                         if not(assigned(protsym)) then
                           begin
                              p1.destroy;

+ 6 - 3
compiler/symtable.pas

@@ -247,7 +247,7 @@ interface
     function  defined_macro(const s : string):boolean;
 
 {*** Object Helpers ***}
-    function search_default_property(pd : tobjectdef) : tpropertysym;
+    function search_default_property(pd : tabstractrecorddef) : tpropertysym;
     function find_real_objcclass_definition(pd: tobjectdef; erroronfailure: boolean): tobjectdef;
 
 {*** Macro Helpers ***}
@@ -2854,7 +2854,7 @@ implementation
                               Object Helpers
 ****************************************************************************}
 
-   function search_default_property(pd : tobjectdef) : tpropertysym;
+   function search_default_property(pd : tabstractrecorddef) : tpropertysym;
    { returns the default property of a class, searches also anchestors }
      var
        _defaultprop : tpropertysym;
@@ -2881,7 +2881,10 @@ implementation
              pd.symtable.SymList.ForEachCall(@tstoredsymtable(pd.symtable).testfordefaultproperty,@_defaultprop);
              if assigned(_defaultprop) then
                break;
-             pd:=pd.childof;
+             if (pd.typ=objectdef) then
+               pd:=tobjectdef(pd).childof
+             else
+               break;
           end;
         search_default_property:=_defaultprop;
      end;

+ 14 - 0
tests/tbf/tb0221.pp

@@ -0,0 +1,14 @@
+{ %fail }
+
+{ should not crash the compiler }
+
+type
+  tr = record
+    a,b: longint;
+  end;
+
+var
+  r: tr;
+begin
+  r[0].a:=1;
+end.