Blaise--- via fpc-devel <fpc-devel@lists.freepascal.org> schrieb am Sa., 19. Dez. 2020, 12:47:
> 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. > Considering that it's only intended for internal use, yes I'm aboard with that. > > > †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<------- > I'd say in this case the bug is that the declaration of those two Cls<> types is allowed. 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...). Regards, Sven >
_______________________________________________ fpc-devel maillist - fpc-devel@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel