* use the correct procdef when taking the address of an overloaded function

in a typed constant (mantis #16820)

git-svn-id: trunk@15508 -
This commit is contained in:
Jonas Maebe 2010-07-02 19:30:20 +00:00
parent 37eed41c52
commit 58362db962
4 changed files with 79 additions and 18 deletions

1
.gitattributes vendored
View File

@ -10523,6 +10523,7 @@ tests/webtbs/tw16770.pp svneol=native#text/plain
tests/webtbs/tw16772.pp svneol=native#text/plain tests/webtbs/tw16772.pp svneol=native#text/plain
tests/webtbs/tw16803.pp svneol=native#text/plain tests/webtbs/tw16803.pp svneol=native#text/plain
tests/webtbs/tw1681.pp svneol=native#text/plain tests/webtbs/tw1681.pp svneol=native#text/plain
tests/webtbs/tw16820.pp svneol=native#text/plain
tests/webtbs/tw1696.pp svneol=native#text/plain tests/webtbs/tw1696.pp svneol=native#text/plain
tests/webtbs/tw1699.pp svneol=native#text/plain tests/webtbs/tw1699.pp svneol=native#text/plain
tests/webtbs/tw1709.pp svneol=native#text/plain tests/webtbs/tw1709.pp svneol=native#text/plain

View File

@ -37,8 +37,8 @@ interface
tloadnode = class(tunarynode) tloadnode = class(tunarynode)
protected protected
procdef : tprocdef; fprocdef : tprocdef;
procdefderef : tderef; fprocdefderef : tderef;
public public
symtableentry : tsym; symtableentry : tsym;
symtableentryderef : tderef; symtableentryderef : tderef;
@ -58,6 +58,7 @@ interface
function docompare(p: tnode): boolean; override; function docompare(p: tnode): boolean; override;
procedure printnodedata(var t:text);override; procedure printnodedata(var t:text);override;
procedure setprocdef(p : tprocdef); procedure setprocdef(p : tprocdef);
property procdef: tprocdef read fprocdef write setprocdef;
end; end;
tloadnodeclass = class of tloadnode; tloadnodeclass = class of tloadnode;
@ -167,7 +168,7 @@ implementation
internalerror(200108121); internalerror(200108121);
symtableentry:=v; symtableentry:=v;
symtable:=st; symtable:=st;
procdef:=nil; fprocdef:=nil;
end; end;
@ -178,7 +179,7 @@ implementation
internalerror(200108122); internalerror(200108122);
symtableentry:=v; symtableentry:=v;
symtable:=st; symtable:=st;
procdef:=d; fprocdef:=d;
end; end;
@ -187,7 +188,7 @@ implementation
inherited ppuload(t,ppufile); inherited ppuload(t,ppufile);
ppufile.getderef(symtableentryderef); ppufile.getderef(symtableentryderef);
symtable:=nil; symtable:=nil;
ppufile.getderef(procdefderef); ppufile.getderef(fprocdefderef);
end; end;
@ -195,7 +196,7 @@ implementation
begin begin
inherited ppuwrite(ppufile); inherited ppuwrite(ppufile);
ppufile.putderef(symtableentryderef); ppufile.putderef(symtableentryderef);
ppufile.putderef(procdefderef); ppufile.putderef(fprocdefderef);
end; end;
@ -203,7 +204,7 @@ implementation
begin begin
inherited buildderefimpl; inherited buildderefimpl;
symtableentryderef.build(symtableentry); symtableentryderef.build(symtableentry);
procdefderef.build(procdef); fprocdefderef.build(fprocdef);
end; end;
@ -212,7 +213,7 @@ implementation
inherited derefimpl; inherited derefimpl;
symtableentry:=tsym(symtableentryderef.resolve); symtableentry:=tsym(symtableentryderef.resolve);
symtable:=symtableentry.owner; symtable:=symtableentry.owner;
procdef:=tprocdef(procdefderef.resolve); fprocdef:=tprocdef(fprocdefderef.resolve);
end; end;
@ -233,7 +234,7 @@ implementation
n:=tloadnode(inherited dogetcopy); n:=tloadnode(inherited dogetcopy);
n.symtable:=symtable; n.symtable:=symtable;
n.symtableentry:=symtableentry; n.symtableentry:=symtableentry;
n.procdef:=procdef; n.fprocdef:=fprocdef;
result:=n; result:=n;
end; end;
@ -322,15 +323,15 @@ implementation
procdefs the matching procdef will be choosen procdefs the matching procdef will be choosen
when the expected procvardef is known, see get_information when the expected procvardef is known, see get_information
in htypechk.pas (PFV) } in htypechk.pas (PFV) }
if not assigned(procdef) then if not assigned(fprocdef) then
procdef:=tprocdef(tprocsym(symtableentry).ProcdefList[0]) fprocdef:=tprocdef(tprocsym(symtableentry).ProcdefList[0])
else if po_kylixlocal in procdef.procoptions then else if po_kylixlocal in fprocdef.procoptions then
CGMessage(type_e_cant_take_address_of_local_subroutine); CGMessage(type_e_cant_take_address_of_local_subroutine);
{ the result is a procdef, addrn and proc_to_procvar { the result is a fprocdef, addrn and proc_to_procvar
typeconvn need this as resultdef so they know typeconvn need this as resultdef so they know
that the address needs to be returned } that the address needs to be returned }
resultdef:=procdef; resultdef:=fprocdef;
{ process methodpointer } { process methodpointer }
if assigned(left) then if assigned(left) then
@ -410,7 +411,7 @@ implementation
docompare := docompare :=
inherited docompare(p) and inherited docompare(p) and
(symtableentry = tloadnode(p).symtableentry) and (symtableentry = tloadnode(p).symtableentry) and
(procdef = tloadnode(p).procdef) and (fprocdef = tloadnode(p).fprocdef) and
(symtable = tloadnode(p).symtable); (symtable = tloadnode(p).symtable);
end; end;
@ -420,14 +421,14 @@ implementation
inherited printnodedata(t); inherited printnodedata(t);
write(t,printnodeindention,'symbol = ',symtableentry.name); write(t,printnodeindention,'symbol = ',symtableentry.name);
if symtableentry.typ=procsym then if symtableentry.typ=procsym then
write(t,printnodeindention,'procdef = ',procdef.mangledname); write(t,printnodeindention,'procdef = ',fprocdef.mangledname);
writeln(t,''); writeln(t,'');
end; end;
procedure tloadnode.setprocdef(p : tprocdef); procedure tloadnode.setprocdef(p : tprocdef);
begin begin
procdef:=p; fprocdef:=p;
resultdef:=p; resultdef:=p;
if po_local in p.procoptions then if po_local in p.procoptions then
CGMessage(type_e_cant_take_address_of_local_subroutine); CGMessage(type_e_cant_take_address_of_local_subroutine);

View File

@ -1005,7 +1005,7 @@ implementation
if (n.nodetype=loadn) and if (n.nodetype=loadn) and
(tloadnode(n).symtableentry.typ=procsym) then (tloadnode(n).symtableentry.typ=procsym) then
begin begin
pd:=tprocdef(tprocsym(tloadnode(n).symtableentry).ProcdefList[0]); pd:=tloadnode(n).procdef;
list.concat(Tai_const.createname(pd.mangledname,0)); list.concat(Tai_const.createname(pd.mangledname,0));
end end
else else

59
tests/webtbs/tw16820.pp Normal file
View File

@ -0,0 +1,59 @@
{$ifdef fpc}
{$mode delphi}{$H+}
{$endif}
uses
Classes, SysUtils;
type
{ TForm1 }
TForm1 = class
private
{ private declarations }
public
{ public declarations }
procedure test;
end;
FNType = function(A, B: integer): integer;
var
Form1: TForm1;
function Add23(A, B: integer; C: cardinal): integer; overload; forward;
function Add23(A, B: integer): integer; overload; forward;
const
FPArray: FNType = Add23;
function Add23(A, B: integer; C: cardinal): integer; overload;
begin
Result := A + B + C;
halt(1);
end;
function Add23(A, B: integer): integer; overload;
begin
Result := A - B;
end;
{ TForm1 }
procedure TForm1.test;
var
a, b: integer;
begin
a := 3;
b := 4;
writeln(FParray(a, b));
end;
var
f: tform1;
begin
f:=tform1.create;
f.test;
f.free;
end.