[fpc-devel] Local classes and interfaces
Blaise at blaise.ru
Blaise at blaise.ru
Sat Dec 19 12:47:04 CET 2020
Behind the scene, the Closures implementation declares classes and interfaces. And, because I strongly believe it to be conceptually the right way, such entities are declared in the innermost routine scope. For example,
-------8<-------
procedure Foo;
type Local = reference to procedure;
begin
end;
-------8<-------
is essentially
-------8<-------
procedure Foo;
type Local = interface
procedure Invoke;
end;
begin
end;
-------8<-------
FPC does not allow the user to declare local classes/interfaces†, and this shall remain so. However, in order to /internally/ support such entities, a couple of changes is required. I have those implemented, but, firstly, let us establish that the team is on board with the general idea.
† No idea why, but generic local classes/interfaces are accepted. However, FPC instantiates them in the global scope, which results in this wonderful bug:
-------8<-------
function Foo: TClass;
type Cls<T> = class end;
begin
result := Cls<Char>
end;
function Bar: TClass;
type Cls<T> = class end;
begin
result := Cls<Char>
end;
begin
// BUG: 'FALSE'
writeln( Foo() <> Bar() )
end.
-------8<-------
--
βþ
More information about the fpc-devel
mailing list