* if an operator overload in a structured type is invalid print an error only for the declaration and not the implementation as well

This fixes Mantis #31634 as far as I see it useful to; anything further would probably require extension of the message generation system by a context or such so that the compiler could write "Error in TFoo<Integer>: ..." instead of merely "Error: ..." or something like that.
No test added due to the nature of the bug.

git-svn-id: trunk@35748 -
This commit is contained in:
svenbarth 2017-04-07 13:24:58 +00:00
parent 199574c7c6
commit 8024fcd7ec
2 changed files with 17 additions and 14 deletions

View File

@ -79,7 +79,7 @@ interface
procedure parse_record_proc_directives(pd:tabstractprocdef); procedure parse_record_proc_directives(pd:tabstractprocdef);
function parse_proc_head(astruct:tabstractrecorddef;potype:tproctypeoption;isgeneric:boolean;genericdef:tdef;generictypelist:tfphashobjectlist;out pd:tprocdef):boolean; function parse_proc_head(astruct:tabstractrecorddef;potype:tproctypeoption;isgeneric:boolean;genericdef:tdef;generictypelist:tfphashobjectlist;out pd:tprocdef):boolean;
function parse_proc_dec(isclassmethod:boolean;astruct:tabstractrecorddef;isgeneric:boolean):tprocdef; function parse_proc_dec(isclassmethod:boolean;astruct:tabstractrecorddef;isgeneric:boolean):tprocdef;
procedure parse_proc_dec_finish(pd:tprocdef;isclassmethod:boolean); procedure parse_proc_dec_finish(pd:tprocdef;isclassmethod:boolean;astruct:tabstractrecorddef);
{ parse a record method declaration (not a (class) constructor/destructor) } { parse a record method declaration (not a (class) constructor/destructor) }
function parse_record_method_dec(astruct: tabstractrecorddef; is_classdef: boolean;hadgeneric:boolean): tprocdef; function parse_record_method_dec(astruct: tabstractrecorddef; is_classdef: boolean;hadgeneric:boolean): tprocdef;
@ -1254,7 +1254,7 @@ implementation
end; end;
procedure parse_proc_dec_finish(pd:tprocdef;isclassmethod:boolean); procedure parse_proc_dec_finish(pd:tprocdef;isclassmethod:boolean;astruct:tabstractrecorddef);
var var
locationstr: string; locationstr: string;
i: integer; i: integer;
@ -1494,12 +1494,15 @@ implementation
else else
MessagePos(pd.fileinfo,type_e_type_id_expected); MessagePos(pd.fileinfo,type_e_type_id_expected);
end; end;
if (optoken in [_ASSIGNMENT,_OP_EXPLICIT]) and if not assigned(pd.struct) or assigned(astruct) then
equal_defs(pd.returndef,tparavarsym(pd.parast.SymList[0]).vardef) and begin
(pd.returndef.typ<>undefineddef) and (tparavarsym(pd.parast.SymList[0]).vardef.typ<>undefineddef) then if (optoken in [_ASSIGNMENT,_OP_EXPLICIT]) and
message(parser_e_no_such_assignment) equal_defs(pd.returndef,tparavarsym(pd.parast.SymList[0]).vardef) and
else if not isoperatoracceptable(pd,optoken) then (pd.returndef.typ<>undefineddef) and (tparavarsym(pd.parast.SymList[0]).vardef.typ<>undefineddef) then
Message(parser_e_overload_impossible); message(parser_e_no_such_assignment)
else if not isoperatoracceptable(pd,optoken) then
Message(parser_e_overload_impossible);
end;
end; end;
end; end;
else else
@ -1556,7 +1559,7 @@ implementation
begin begin
{ pd=nil when it is a interface mapping } { pd=nil when it is a interface mapping }
if assigned(pd) then if assigned(pd) then
parse_proc_dec_finish(pd,isclassmethod) parse_proc_dec_finish(pd,isclassmethod,astruct)
else else
finish_intf_mapping; finish_intf_mapping;
end end
@ -1576,7 +1579,7 @@ implementation
begin begin
{ pd=nil when it is an interface mapping } { pd=nil when it is an interface mapping }
if assigned(pd) then if assigned(pd) then
parse_proc_dec_finish(pd,isclassmethod) parse_proc_dec_finish(pd,isclassmethod,astruct)
else else
finish_intf_mapping; finish_intf_mapping;
end end
@ -1592,7 +1595,7 @@ implementation
else else
recover:=not parse_proc_head(astruct,potype_constructor,false,nil,nil,pd); recover:=not parse_proc_head(astruct,potype_constructor,false,nil,nil,pd);
if not recover then if not recover then
parse_proc_dec_finish(pd,isclassmethod); parse_proc_dec_finish(pd,isclassmethod,astruct);
end; end;
_DESTRUCTOR : _DESTRUCTOR :
@ -1603,7 +1606,7 @@ implementation
else else
recover:=not parse_proc_head(astruct,potype_destructor,false,nil,nil,pd); recover:=not parse_proc_head(astruct,potype_destructor,false,nil,nil,pd);
if not recover then if not recover then
parse_proc_dec_finish(pd,isclassmethod); parse_proc_dec_finish(pd,isclassmethod,astruct);
end; end;
else else
if (token=_OPERATOR) or if (token=_OPERATOR) or
@ -1618,7 +1621,7 @@ implementation
parse_proc_head(astruct,potype_operator,false,nil,nil,pd); parse_proc_head(astruct,potype_operator,false,nil,nil,pd);
block_type:=old_block_type; block_type:=old_block_type;
if assigned(pd) then if assigned(pd) then
parse_proc_dec_finish(pd,isclassmethod) parse_proc_dec_finish(pd,isclassmethod,astruct)
else else
begin begin
{ recover } { recover }

View File

@ -1018,7 +1018,7 @@ uses
pd.procsym:=psym pd.procsym:=psym
else else
pd.procsym:=srsym; pd.procsym:=srsym;
parse_proc_dec_finish(pd,po_classmethod in tprocdef(genericdef).procoptions); parse_proc_dec_finish(pd,po_classmethod in tprocdef(genericdef).procoptions,tprocdef(genericdef).struct);
end; end;
result:=pd; result:=pd;
end end