瀏覽代碼

* throw an error if a second forward type declaration is found at the place of this second
declaration, resolves #41150

florian 3 月之前
父節點
當前提交
f971398f47
共有 3 個文件被更改,包括 52 次插入20 次删除
  1. 3 0
      compiler/msg/errore.msg
  2. 24 20
      compiler/pdecobj.pas
  3. 25 0
      tests/webtbf/tw41150.pp

+ 3 - 0
compiler/msg/errore.msg

@@ -1698,6 +1698,9 @@ parser_e_coperators_off=03371_E_C styled assignment operators are turned off
 parser_e_cannot_evaluate_expression_at_compile_time=03372_E_Expression cannot be evaluated at compile time
 % Certain operations like the size of an object cannot be determined at compile time,
 % so it cannot be e.g. part of a constant expression.
+parser_e_type_alread_forward=03373_E_Duplicate forward type declaration: $1
+% Types might be defined only once as forward:
+% \var{type myclass = class; myclass = class;} is not allowed
 %
 % \end{description}
 %

+ 24 - 20
compiler/pdecobj.pas

@@ -1620,27 +1620,31 @@ implementation
           parse_object_options;
 
         { forward def? }
-        if not assigned(fd) and
-           (token=_SEMICOLON) then
+        if token=_SEMICOLON then
           begin
-            if is_objectpascal_helper(current_structdef) then
-              consume(_FOR);
-            { add to the list of definitions to check that the forward
-              is resolved. this is required for delphi mode }
-            current_module.checkforwarddefs.add(current_structdef);
-
-            symtablestack.push(current_structdef.symtable);
-            insert_generic_parameter_types(current_structdef,genericdef,genericlist,false);
-            { when we are parsing a generic already then this is a generic as
-              well }
-            if old_parse_generic then
-              include(current_structdef.defoptions,df_generic);
-            parse_generic:=(df_generic in current_structdef.defoptions);
-
-            { *don't* add the strict private symbol for non-Delphi modes for
-              forward defs }
-
-            symtablestack.pop(current_structdef.symtable);
+            if assigned(fd) then
+              Message1(parser_e_type_alread_forward,n)
+            else
+              begin
+                if is_objectpascal_helper(current_structdef) then
+                  consume(_FOR);
+                { add to the list of definitions to check that the forward
+                  is resolved. this is required for delphi mode }
+                current_module.checkforwarddefs.add(current_structdef);
+
+                symtablestack.push(current_structdef.symtable);
+                insert_generic_parameter_types(current_structdef,genericdef,genericlist,false);
+                { when we are parsing a generic already then this is a generic as
+                  well }
+                if old_parse_generic then
+                  include(current_structdef.defoptions,df_generic);
+                parse_generic:=(df_generic in current_structdef.defoptions);
+
+                { *don't* add the strict private symbol for non-Delphi modes for
+                  forward defs }
+
+                symtablestack.pop(current_structdef.symtable);
+              end;
           end
         else
           begin

+ 25 - 0
tests/webtbf/tw41150.pp

@@ -0,0 +1,25 @@
+{ %fail }
+{$mode delphi}
+
+type
+
+     TSomeClass = class;
+
+
+
+
+     TSomeClass = class;
+
+
+
+
+
+
+
+
+
+     TSomeClass = class  // duplicate identifier on this line.
+                end;
+
+begin
+end.