2
0
Эх сурвалжийг харах

* var, type, threadvar, const sections require also in classes etc. at least one declaration, resolves #39599

florian 3 жил өмнө
parent
commit
9e3f647333

+ 13 - 1
compiler/pdecobj.pas

@@ -1194,18 +1194,27 @@ implementation
                   Message(parser_e_type_var_const_only_in_records_and_classes);
                 consume(_TYPE);
                 object_member_blocktype:=bt_type;
+                { expect at least one type declaration }
+                if token<>_ID then
+                  consume(_ID);
               end;
             _VAR :
               begin
                 check_unbound_attributes;
                 rtti_attrs_def := nil;
                 parse_var(false);
+                { expect at least one var declaration }
+                if token<>_ID then
+                  consume(_ID);
               end;
             _CONST:
               begin
                 check_unbound_attributes;
                 rtti_attrs_def := nil;
-                parse_const
+                parse_const;
+                { expect at least one constant declaration }
+                if token<>_ID then
+                  consume(_ID);
               end;
             _THREADVAR :
               begin
@@ -1217,6 +1226,9 @@ implementation
                     is_classdef:=true;
                   end;
                 parse_var(true);
+                { expect at least one threadvar declaration }
+                if token<>_ID then
+                  consume(_ID);
               end;
             _ID :
               begin

+ 10 - 0
tests/webtfs/tw39599a.pp

@@ -0,0 +1,10 @@
+{ %fail }
+program project1;
+{$mode objfpc}
+type
+  TMyClass = class(TObject)
+  const
+    procedure A; virtual; abstract; // should not be allowed
+  end;
+begin
+end.

+ 10 - 0
tests/webtfs/tw39599b.pp

@@ -0,0 +1,10 @@
+{ %fail }
+program project1;
+{$mode objfpc}
+type
+  TMyClass = class(TObject)
+  type
+    procedure A; virtual; abstract; // should not be allowed
+  end;
+begin
+end.

+ 10 - 0
tests/webtfs/tw39599c.pp

@@ -0,0 +1,10 @@
+{ %fail }
+program project1;
+{$mode objfpc}
+type
+  TMyClass = class(TObject)
+  var
+    procedure A; virtual; abstract; // should not be allowed
+  end;
+begin
+end.

+ 10 - 0
tests/webtfs/tw39599d.pp

@@ -0,0 +1,10 @@
+{ %fail }
+program project1;
+{$mode objfpc}
+type
+  TMyClass = class(TObject)
+  threadvar
+    procedure A; virtual; abstract; // should not be allowed
+  end;
+begin
+end.