Forráskód Böngészése

* better error recovery, resolves #39485

florian 3 éve
szülő
commit
c6874df5c8
2 módosított fájl, 40 hozzáadás és 5 törlés
  1. 20 5
      compiler/pdecobj.pas
  2. 20 0
      tests/tbf/tw39485.pp

+ 20 - 5
compiler/pdecobj.pas

@@ -165,6 +165,8 @@ implementation
     procedure struct_property_dec(is_classproperty:boolean;var rtti_attrs_def: trtti_attribute_list);
       var
         p : tpropertysym;
+        _deprecatedmsg: pshortstring;
+        _symoptions: tsymoptions;
       begin
         { check for a class, record or helper }
         if not((is_class_or_interface_or_dispinterface(current_structdef) or is_record(current_structdef) or
@@ -214,12 +216,25 @@ implementation
               Message(parser_e_enumerator_identifier_required);
             consume(_SEMICOLON);
           end;
-        trtti_attribute_list.bind(rtti_attrs_def,p.rtti_attribute_list);
+        { in case of a previous error, p might not be assigned }
+        if assigned(p) then
+          begin
+            trtti_attribute_list.bind(rtti_attrs_def,p.rtti_attribute_list);
+
+            { hint directives, these can be separated by semicolons here,
+              that needs to be handled here with a loop (PFV) }
+            while try_consume_hintdirective(p.symoptions,p.deprecatedmsg) do
+              Consume(_SEMICOLON);
+          end
+        else
+          begin
+            { recover from error so we can continue to parse }
 
-        { hint directives, these can be separated by semicolons here,
-          that needs to be handled here with a loop (PFV) }
-        while try_consume_hintdirective(p.symoptions,p.deprecatedmsg) do
-          Consume(_SEMICOLON);
+            { hint directives, these can be separated by semicolons here,
+              that needs to be handled here with a loop (PFV) }
+            while try_consume_hintdirective(_symoptions,_deprecatedmsg) do
+              Consume(_SEMICOLON);
+          end;
       end;
 
 

+ 20 - 0
tests/tbf/tw39485.pp

@@ -0,0 +1,20 @@
+{ %fail }
+program Project1;
+{$mode objfpc}{$H+}{$Interfaces CORBA}
+
+type
+  ITest = interface
+  end;
+
+  TBar = class;
+
+  TFoo = class(TObject, ITest)
+    Fa: TBar;
+    property a: TBar read Fa implements ITest;
+  end;
+
+  TBar = class(TObject, ITest)
+  end;
+
+begin
+end.