mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-06-21 12:38:21 +02:00
Don't allow "static" for class operators or normal methods (except in objects).
pdecsub.pas, pd_static: * check whether the given pd is an operator or a class method not inside an Object and generate an error if either of these is true msg/errore.msg, msgidx.inc, msgtxt.inc: * add a message to inform that a certain procedure directive is not allowed + added tests git-svn-id: trunk@23944 -
This commit is contained in:
parent
0b358e8554
commit
376bd046aa
3
.gitattributes
vendored
3
.gitattributes
vendored
@ -9244,6 +9244,9 @@ tests/tbf/tb0227.pp svneol=native#text/pascal
|
|||||||
tests/tbf/tb0228.pp svneol=native#text/pascal
|
tests/tbf/tb0228.pp svneol=native#text/pascal
|
||||||
tests/tbf/tb0229.pp svneol=native#text/pascal
|
tests/tbf/tb0229.pp svneol=native#text/pascal
|
||||||
tests/tbf/tb0230.pp svneol=native#text/pascal
|
tests/tbf/tb0230.pp svneol=native#text/pascal
|
||||||
|
tests/tbf/tb0231.pp svneol=native#text/pascal
|
||||||
|
tests/tbf/tb0232.pp svneol=native#text/pascal
|
||||||
|
tests/tbf/tb0233.pp svneol=native#text/pascal
|
||||||
tests/tbf/ub0115.pp svneol=native#text/plain
|
tests/tbf/ub0115.pp svneol=native#text/plain
|
||||||
tests/tbf/ub0149.pp svneol=native#text/plain
|
tests/tbf/ub0149.pp svneol=native#text/plain
|
||||||
tests/tbf/ub0158a.pp svneol=native#text/plain
|
tests/tbf/ub0158a.pp svneol=native#text/plain
|
||||||
|
@ -392,7 +392,7 @@ scan_w_setpeoptflags_not_support=02092_W_SETPEOPTFLAGS is not supported by the t
|
|||||||
#
|
#
|
||||||
# Parser
|
# Parser
|
||||||
#
|
#
|
||||||
# 03332 is the last used one
|
# 03333 is the last used one
|
||||||
#
|
#
|
||||||
% \section{Parser messages}
|
% \section{Parser messages}
|
||||||
% This section lists all parser messages. The parser takes care of the
|
% This section lists all parser messages. The parser takes care of the
|
||||||
@ -1487,6 +1487,9 @@ parser_e_not_allowed_in_record=03332_E_Visibility section "$1" not allowed in re
|
|||||||
% The visibility sections \var(protected) and \var(strict protected) are only
|
% The visibility sections \var(protected) and \var(strict protected) are only
|
||||||
% useful together with inheritance. Since records do not support that they are
|
% useful together with inheritance. Since records do not support that they are
|
||||||
% forbidden.
|
% forbidden.
|
||||||
|
parser_e_proc_dir_not_allowed=03333_E_Procedure directive "$1" not allowed here
|
||||||
|
% This procedure directive is not allowed in the given context. E.g. "static"
|
||||||
|
% is not allowed for instance methods or class operators.
|
||||||
%
|
%
|
||||||
%
|
%
|
||||||
% \end{description}
|
% \end{description}
|
||||||
|
@ -428,6 +428,7 @@ const
|
|||||||
parser_e_no_properties_in_local_anonymous_records=03330;
|
parser_e_no_properties_in_local_anonymous_records=03330;
|
||||||
parser_e_no_class_in_local_anonymous_records=03331;
|
parser_e_no_class_in_local_anonymous_records=03331;
|
||||||
parser_e_not_allowed_in_record=03332;
|
parser_e_not_allowed_in_record=03332;
|
||||||
|
parser_e_proc_dir_not_allowed=03333;
|
||||||
type_e_mismatch=04000;
|
type_e_mismatch=04000;
|
||||||
type_e_incompatible_types=04001;
|
type_e_incompatible_types=04001;
|
||||||
type_e_not_equal_types=04002;
|
type_e_not_equal_types=04002;
|
||||||
@ -972,9 +973,9 @@ const
|
|||||||
option_info=11024;
|
option_info=11024;
|
||||||
option_help_pages=11025;
|
option_help_pages=11025;
|
||||||
|
|
||||||
MsgTxtSize = 68811;
|
MsgTxtSize = 68861;
|
||||||
|
|
||||||
MsgIdxMax : array[1..20] of longint=(
|
MsgIdxMax : array[1..20] of longint=(
|
||||||
26,93,333,121,88,56,126,27,202,63,
|
26,93,334,121,88,56,126,27,202,63,
|
||||||
54,20,1,1,1,1,1,1,1,1
|
54,20,1,1,1,1,1,1,1,1
|
||||||
);
|
);
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1611,8 +1611,19 @@ end;
|
|||||||
|
|
||||||
procedure pd_static(pd:tabstractprocdef);
|
procedure pd_static(pd:tabstractprocdef);
|
||||||
begin
|
begin
|
||||||
if pd.typ=procdef then
|
if pd.typ<>procdef then
|
||||||
include(tprocdef(pd).procsym.symoptions,sp_static);
|
internalerror(2013032001);
|
||||||
|
if not assigned(tprocdef(pd).struct) then
|
||||||
|
internalerror(2013032002);
|
||||||
|
include(tprocdef(pd).procsym.symoptions,sp_static);
|
||||||
|
{ "static" is not allowed for operators or normal methods (except in objects) }
|
||||||
|
if (pd.proctypeoption=potype_operator) or
|
||||||
|
(
|
||||||
|
not (po_classmethod in pd.procoptions) and
|
||||||
|
not is_object(tprocdef(pd).struct)
|
||||||
|
)
|
||||||
|
then
|
||||||
|
Message1(parser_e_proc_dir_not_allowed,arraytokeninfo[_STATIC].str);
|
||||||
include(pd.procoptions,po_staticmethod);
|
include(pd.procoptions,po_staticmethod);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
19
tests/tbf/tb0231.pp
Normal file
19
tests/tbf/tb0231.pp
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
{ %FAIL }
|
||||||
|
|
||||||
|
program tb0231;
|
||||||
|
|
||||||
|
{$mode objfpc}
|
||||||
|
|
||||||
|
type
|
||||||
|
TTest = class
|
||||||
|
procedure Test; static;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTest.Test;
|
||||||
|
begin
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
|
begin
|
||||||
|
|
||||||
|
end.
|
20
tests/tbf/tb0232.pp
Normal file
20
tests/tbf/tb0232.pp
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
{ %FAIL }
|
||||||
|
|
||||||
|
program tb0232;
|
||||||
|
|
||||||
|
{$mode objfpc}
|
||||||
|
{$modeswitch advancedrecords}
|
||||||
|
|
||||||
|
type
|
||||||
|
TTest = record
|
||||||
|
procedure Test; static;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTest.Test;
|
||||||
|
begin
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
|
begin
|
||||||
|
|
||||||
|
end.
|
20
tests/tbf/tb0233.pp
Normal file
20
tests/tbf/tb0233.pp
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
{ %FAIL }
|
||||||
|
|
||||||
|
program tb0233;
|
||||||
|
|
||||||
|
{$mode objfpc}
|
||||||
|
{$modeswitch advancedrecords}
|
||||||
|
|
||||||
|
type
|
||||||
|
TTest = record
|
||||||
|
class operator + (aLeft, aRight: TTest): TTest; static;
|
||||||
|
end;
|
||||||
|
|
||||||
|
class operator TTest.+(aLeft, aRight: TTest): TTest;
|
||||||
|
begin
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
|
begin
|
||||||
|
|
||||||
|
end.
|
Loading…
Reference in New Issue
Block a user