<div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Blaise--- via fpc-devel <<a href="mailto:fpc-devel@lists.freepascal.org">fpc-devel@lists.freepascal.org</a>> schrieb am Sa., 19. Dez. 2020, 12:47:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">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,<br>
-------8<-------<br>
procedure Foo;<br>
        type Local = reference to procedure;<br>
begin<br>
end;<br>
-------8<-------<br>
is essentially<br>
-------8<-------<br>
procedure Foo;<br>
        type Local = interface<br>
                procedure Invoke;<br>
        end;<br>
begin<br>
end;<br>
-------8<-------<br>
<br>
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.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">Considering that it's only intended for internal use, yes I'm aboard with that. </div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<br>
† No idea why, but generic local classes/interfaces are accepted. However, FPC instantiates them in the global scope, which results in this wonderful bug:<br>
-------8<-------<br>
function Foo: TClass;<br>
        type Cls<T> = class end;<br>
begin<br>
        result := Cls<Char><br>
end;<br>
<br>
function Bar: TClass;<br>
        type Cls<T> = class end;<br>
begin<br>
        result := Cls<Char><br>
end;<br>
<br>
begin<br>
        // BUG: 'FALSE'<br>
        writeln( Foo() <> Bar() )<br>
end.<br>
-------8<-------<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">I'd say in this case the bug is that the declaration of those two Cls<> types is allowed.</div><div dir="auto"><br></div><div dir="auto">By the way: If I remember correctly *specializations* are already placed in the more nested scope if they use local types (or at least that was the plan, I think there are still some bugs left there...). </div><div dir="auto"><br></div><div dir="auto">Regards, </div><div dir="auto">Sven </div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote></div></div></div>