* apply patch by Blaise.ru: proper code generation for assigning class non-static methods, accessed via a class reference type, to method pointers

+ added test
This commit is contained in:
Sven/Sarah Barth 2022-01-06 21:59:11 +01:00
parent 6e7a82440e
commit bc4eb00a7a
2 changed files with 25 additions and 1 deletions

View File

@ -1076,7 +1076,12 @@ implementation
else
begin
typecheckpass(p1);
if (p1.resultdef.typ=objectdef) then
if (p1.resultdef.typ=classrefdef) and assigned(getprocvardef) then
begin
p1:=cloadvmtaddrnode.create(p1);
tloadnode(p2).set_mp(p1);
end
else if (p1.resultdef.typ=objectdef) then
{ so we can create the correct method pointer again in case
this is a "objectprocvar:=@classname.method" expression }
tloadnode(p2).symtable:=tobjectdef(p1.resultdef).symtable

19
tests/test/tprocvar16.pp Normal file
View File

@ -0,0 +1,19 @@
program tprocvar16;
{$mode delphi}
type C = class
class procedure Foo;
end;
class procedure C.Foo; begin end;
type CC = class of C;
var Z: procedure of object;
begin
Z := CC.Foo;
if TMethod(Z).Code <> @C.Foo then
Halt(1);
if TMethod(Z).Data <> Pointer(C) then
Halt(2);
end.