www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22578] New: Symbols exposed by means of compile-time


          Issue ID: 22578
           Summary: Symbols exposed by means of compile-time evaluation
                    are not eligible for selective imports.
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: andrei erdani.com

This may not be fixable either on principle or on account of being too onerous
to implement or support.

Among the implementation mechanisms for versioning (see e.g.
https://github.com/dlang/phobos/pull/8309) we need a means to expose symbols in
a controlled manner. One possibility is to do so programmatically by means of
introspection and code generation, e.g.:

static foreach (s; __traits(allMembers, canon!"std"))
    mixin("alias "~s~" = canon!`std`."~s~";");

This code exposes symbols such as `std.algorithm.comparison.canon!"std".among`
as `std.algorithm.comparison.among`. It has the usual automation advantages
compared with repeated alias directives:

alias among = canon!"std".among;

However (and this is the subject of this issue), symbols exported by means of
`static foreach` and `mixin` are not usable in selective imports. For example,
if another module attempts:

import std.algorithm.comparison : among;

then the symbol exposed with a plain `alias` will work, but the symbol exposed
programmatically will not.

Dec 07 2021