compiler: disallow regular class methods in records and allow only static class methods. delphi do so and it is logical because records have no inheritance. + tests

git-svn-id: branches/paul/extended_records@16550 -
This commit is contained in:
paul 2010-12-11 10:21:09 +00:00
parent 17815ce7a2
commit 582ab2dd32
7 changed files with 357 additions and 328 deletions

1
.gitattributes vendored
View File

@ -9207,6 +9207,7 @@ tests/test/terecs1.pp svneol=native#text/pascal
tests/test/terecs2.pp svneol=native#text/pascal
tests/test/terecs3.pp svneol=native#text/pascal
tests/test/terecs4.pp svneol=native#text/pascal
tests/test/terecs5.pp svneol=native#text/pascal
tests/test/terecs_u1.pp svneol=native#text/pascal
tests/test/testcmem.pp svneol=native#text/plain
tests/test/testda1.pp svneol=native#text/plain

View File

@ -1310,7 +1310,6 @@ parser_e_no_paras_for_class_constructor=03290_E_Class constructors can't have pa
parser_e_no_paras_for_class_destructor=03291_E_Class destructors can't have parameters
% You are declaring a class destructor with a parameter list. Class destructor methods
% cannot have parameters.
parser_f_modeswitch_objc_required=03292_F_This construct requires the \{\$modeswitch objectivec1\} mode switch to be active
% Objective-Pascal constructs are not supported when \{\$modeswitch ObjectiveC1\}
% is not active.
@ -1346,6 +1345,9 @@ parser_e_no_record_published=03298_E_Record types cannot have published sections
% Published sections can be used only inside classes.
parser_e_no_destructor_in_records=03299_E_Destructors aren't allowed in records
% Destructor declarations aren't allowed in records.
parser_e_class_methods_only_static_in_records=03300_E_Class methods must be static in records
% Class methods declarations aren't allowed in records without static modifier.
% Records have no inheritance and therefore non static class methods have no sence for them.
#
# Type Checking
#

View File

@ -388,6 +388,7 @@ const
parser_f_no_generic_inside_generic=03297;
parser_e_no_record_published=03298;
parser_e_no_destructor_in_records=03299;
parser_e_class_methods_only_static_in_records=03300;
type_e_mismatch=04000;
type_e_incompatible_types=04001;
type_e_not_equal_types=04002;
@ -873,9 +874,9 @@ const
option_info=11024;
option_help_pages=11025;
MsgTxtSize = 58003;
MsgTxtSize = 58051;
MsgIdxMax : array[1..20] of longint=(
24,88,300,97,82,54,111,22,202,63,
24,88,301,97,82,54,111,22,202,63,
49,20,1,1,1,1,1,1,1,1
);

File diff suppressed because it is too large Load Diff

View File

@ -732,6 +732,12 @@ implementation
if assigned(pd) then
begin
parse_record_proc_directives(pd);
{ since records have no inheritance don't allow non static
class methods. delphi do so. }
if is_classdef and not (po_staticmethod in pd.procoptions) then
MessagePos(pd.fileinfo, parser_e_class_methods_only_static_in_records);
handle_calling_convention(pd);
{ add definition to procsym }

17
tests/test/terecs5.pp Normal file
View File

@ -0,0 +1,17 @@
{ %fail}
{ %norun}
program terecs5;
{$mode delphi}
type
TFoo = record
class procedure Test; // not allowed without static
end;
class procedure TFoo.Test;
begin
end;
begin
end.

View File

@ -22,7 +22,7 @@ type
class var
F5: TBar;
function Test(n: TBar): TBar;
class function Test1(n: TBar): TBar;
class function Test1(n: TBar): TBar; static;
procedure Set3(const Value: TBar);
class procedure Set5(const Value: TBar); static;