Am 23.12.2021 um 19:13 schrieb Blaise--- via fpc-devel:
Subj silently produces invalid codegen:
-------8<-------
var Z: procedure of object;
type R = record
procedure Foo;
end;
procedure R.Foo; begin end;
type O = object
procedure Foo;
end;
procedure O.Foo; begin end;
type C = class
procedure Foo;
class procedure ClassCtx;
end;
procedure C.Foo; begin end;
class procedure C.ClassCtx;
begin
Z := Foo; // BadCG: .Code = C.Foo; .Data = C
end;
type CC = class of C;
var aCC: CC = nil;
type H = class helper for C
procedure Bar;
class procedure ClassCtx2;
end;
procedure H.Bar; begin end;
class procedure H.ClassCtx2;
begin
Z := Bar; // BadCG: .Code = H.Bar; .Data = C
end;
begin
Z := R.Foo; // BadCG: GARBAGE
Z := O.Foo; // BadCG: GARBAGE
Z := C.Foo; // BadCG: .Code = C.Foo; .Data = C
Z := CC.Foo; // BadCG: GARBAGE
Z := aCC.Foo; // BadCG: .Code = C.Foo; .Data = aCC
// Currently allowed, and we get the fix for this for free.
// Such qualification may become rejected;
// see
https://lists.freepascal.org/pipermail/fpc-devel/2021-December/044251.html
Z := H.Bar; // BadCG: GARBAGE
end.
-------8<-------
The attached methptr_to_instancemeth_via_type.patch catches all these
cases and reports the proper error:
Error: Only class methods, class properties and class variables can
be referred with class references
Accepted.
Regards,
Sven
_______________________________________________
fpc-devel maillist - fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel