[Issue 22578] New: Symbols exposed by means of compile-time evaluation are not eligible for selective imports.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Dec 7 19:34:52 UTC 2021


https://issues.dlang.org/show_bug.cgi?id=22578

          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 at puremagic.com
          Reporter: andrei at 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.

--


More information about the Digitalmars-d-bugs mailing list