Time for std.reflection

David Nadlinger see at klickverbot.at
Mon Jul 23 05:43:20 PDT 2012


On Sunday, 22 July 2012 at 13:39:31 UTC, Philippe Sigaud wrote:
> 4) How would that allows queries like "Here is class C, give me 
> all
> its available subclasses."? Hmm, wait, I get it: extract 
> classes from
> the module, and recursively from imported modules. From these 
> classes,
> extract the parent classes and so on, until the search ranged 
> over the
> whole inheritance tree. I guess inheritance info could be 
> standard
> enough for std.reflection to provide such a search.

You can't do that without breaking the module system – as long 
as a class is not final (and then it doesn't make much sense to 
ask for its subclasses anyway), somebody can always extend it in 
a module completely separate from the code making the query.

To illustrate what I mean, let's assume you define a class Foo in 
a module A. The user imports A from a second module B, and 
potentially extends Foo there. Now, if it was possible to get all 
possible subclasses in A, this would lead to information leaking 
from B to A, while the import graph only allows the other 
direction. As a consequence, all kinds of issues related to order 
dependence, separate compilation, etc. would arise.

David


More information about the Digitalmars-d mailing list