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

This commit is contained in:
florian 2022-02-25 21:56:09 +01:00
parent d36761f4a4
commit 9e3f647333
5 changed files with 53 additions and 1 deletions

View File

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

10
tests/webtfs/tw39599a.pp Normal file
View File

@ -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
tests/webtfs/tw39599b.pp Normal file
View File

@ -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
tests/webtfs/tw39599c.pp Normal file
View File

@ -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
tests/webtfs/tw39599d.pp Normal file
View File

@ -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.