[fpc-devel] Assigning class non-static methods, accessed via a helper type, to method pointers

Blaise at blaise.ru Blaise at blaise.ru
Thu Dec 23 15:12:26 CET 2021


Subj silently produces invalid codegen:
-------8<-------
type C = class end;
type H = class helper for C
	class procedure Bar;
end;
class procedure H.Bar;
begin
	writeln('H.Bar(self=', ClassName, ')')
end;

var Z: procedure of object;
begin
	Z := H.Bar; // BadCG: GARBAGE
	// H.Bar; // REJECTED
end.
-------8<-------

What is the consensus on:
A) fixing the codegen?
B) rejecting such access?

DCC does reject both statements, but it is not consistent with rejecting such qualifications everywhere.

Practically, allowing such qualifications could be useful for selecting a particular method. For example:
-------8<-------
type H2 = class helper (H) for C
	class procedure Bar;
end;
-------8<-------

Also, despite the comment in tcallnode.pass_1 saying:
> 	CGMessage(parser_e_no_category_as_types);
> 	{ we get an internal error when trying to insert the hidden
> 	parameters in this case }
when I comment out the call to CGMessage, I get no ICE for
	H.Bar
only EXTDEBUG warnings:
> Warning: Expectloc is not set in firstpass: calln
> Warning: ExpectLoc is not set before secondpass: calln
> Warning: Location (LOC_VOID) not equal to expectloc (LOC_INVALID): calln
and invalid codegen.

-- 
βþ


More information about the fpc-devel mailing list