mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-19 07:19:26 +02:00
compiler: require at least one argument of class operator to be of type of structure where this operator is declared
git-svn-id: trunk@16644 -
This commit is contained in:
parent
b25f51e2e1
commit
51a9d3280c
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -9329,6 +9329,7 @@ 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/terecs6.pp svneol=native#text/pascal
|
||||
tests/test/terecs7.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
|
||||
|
@ -368,7 +368,7 @@ scanner_w_illegal_warn_identifier=02087_W_Illegal identifier "$1" for $WARN dire
|
||||
#
|
||||
# Parser
|
||||
#
|
||||
# 03302 is the last used one
|
||||
# 03303 is the last used one
|
||||
#
|
||||
% \section{Parser messages}
|
||||
% This section lists all parser messages. The parser takes care of the
|
||||
@ -1360,6 +1360,9 @@ parser_e_class_methods_only_static_in_records=03301_E_Class methods must be stat
|
||||
parser_e_no_constructor_in_records=03302_E_Constructors aren't allowed in records
|
||||
% Constructor declarations aren't allowed in records.
|
||||
% \end{description}
|
||||
parser_e_at_least_one_argument_must_be_of_type=03303_E_At least one argument must be of type "$1"
|
||||
% It is required that at least one argument be of type of structure where this method is defined.
|
||||
% For example class operators must contain at least one argument of the structure where they are defined.
|
||||
#
|
||||
# Type Checking
|
||||
#
|
||||
|
@ -391,6 +391,7 @@ const
|
||||
parser_e_no_destructor_in_records=03300;
|
||||
parser_e_class_methods_only_static_in_records=03301;
|
||||
parser_e_no_constructor_in_records=03302;
|
||||
parser_e_at_least_one_argument_must_be_of_type=03303;
|
||||
type_e_mismatch=04000;
|
||||
type_e_incompatible_types=04001;
|
||||
type_e_not_equal_types=04002;
|
||||
@ -876,9 +877,9 @@ const
|
||||
option_info=11024;
|
||||
option_help_pages=11025;
|
||||
|
||||
MsgTxtSize = 58219;
|
||||
MsgTxtSize = 58270;
|
||||
|
||||
MsgIdxMax : array[1..20] of longint=(
|
||||
24,88,303,97,82,54,111,22,202,63,
|
||||
24,88,304,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
@ -1182,8 +1182,10 @@ implementation
|
||||
|
||||
function parse_proc_dec(isclassmethod:boolean;astruct:tabstractrecorddef):tprocdef;
|
||||
var
|
||||
pd : tprocdef;
|
||||
pd: tprocdef;
|
||||
locationstr: string;
|
||||
i: integer;
|
||||
found: boolean;
|
||||
|
||||
procedure read_returndef(pd: tprocdef);
|
||||
var
|
||||
@ -1377,6 +1379,18 @@ implementation
|
||||
else
|
||||
begin
|
||||
read_returndef(pd);
|
||||
if (po_classmethod in pd.procoptions) then
|
||||
begin
|
||||
found:=false;
|
||||
for i := 0 to pd.parast.SymList.Count - 1 do
|
||||
if tparavarsym(pd.parast.SymList[0]).vardef=pd.struct then
|
||||
begin
|
||||
found:=true;
|
||||
break;
|
||||
end;
|
||||
if not found then
|
||||
Message1(parser_e_at_least_one_argument_must_be_of_type,pd.struct.RttiName);
|
||||
end;
|
||||
if (optoken in [_EQ,_NE,_GT,_LT,_GTE,_LTE,_OP_IN]) and
|
||||
((pd.returndef.typ<>orddef) or
|
||||
(torddef(pd.returndef).ordtype<>pasbool)) then
|
||||
|
24
tests/test/terecs7.pp
Normal file
24
tests/test/terecs7.pp
Normal file
@ -0,0 +1,24 @@
|
||||
{ %fail }
|
||||
program terecs7;
|
||||
|
||||
{$MODE DELPHI}
|
||||
{$APPTYPE CONSOLE}
|
||||
|
||||
type
|
||||
TBar = record
|
||||
end;
|
||||
|
||||
TFoo = record
|
||||
class operator GreaterThan(i, j: TBar): Boolean;
|
||||
end;
|
||||
|
||||
{ TFoo }
|
||||
|
||||
class operator TFoo.GreaterThan(i, j: TBar): Boolean;
|
||||
begin
|
||||
|
||||
end;
|
||||
|
||||
begin
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user