* fix #39981: retrieve the symbol that returns the desired procdef/procvardef not maybe the Self or something else as we need that symbol to differentiate the procdefs

+ added test
This commit is contained in:
Sven/Sarah Barth 2022-11-06 16:52:38 +01:00
parent 3c2703787c
commit a714e2ff35
2 changed files with 54 additions and 0 deletions

View File

@ -755,6 +755,8 @@ implementation
result:=fen_false;
if n.nodetype<>loadn then
exit;
if not (n.resultdef.typ in [procdef,procvardef]) then
exit;
sym^:=tloadnode(n).symtableentry;
result:=fen_norecurse_true;
end;

52
tests/webtbs/tw39981.pp Normal file
View File

@ -0,0 +1,52 @@
program tw39981;
{$mode objfpc}{$H+}
{$ModeSwitch functionreferences}
type
TNotifyProc = reference to procedure();
TMyClass = class
public
procedure One;
procedure Two;
end;
{ TMyClass }
var
OneCounter: Integer = 0;
TwoCounter: Integer = 0;
procedure TMyClass.One;
begin
Writeln('One');
Inc(OneCounter);
end;
procedure TMyClass.Two;
begin
Writeln('Two');
Inc(TwoCounter);
end;
var
One, Two: TNotifyProc;
MyObject: TMyClass;
HasError: Boolean = False;
begin
MyObject := TMyClass.Create;
One := @MyObject.One;
Two := @MyObject.Two;
One(); // writes out One - OK
Two(); // writes out One - Error
if One=Two then // yes, they are equal - Error
HasError := True;
if not ((OneCounter=1) and (TwoCounter=1)) then // Error: OneCounter=2, TwoCounter=0
HasError := True;
if HasError then
Halt(1);
end.