www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20915] New: __traits(allMembers) results include custom

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

          Issue ID: 20915
           Summary: __traits(allMembers) results include custom version
                    identifiers, which is unusable
           Product: D
           Version: D2
          Hardware: All
               URL: https://forum.dlang.org/post/xnjziupykkmgsxvmnufe foru
                    m.dlang.org
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: b2.temp gmx.com

There's no way to identify a custom version identifier as such.
Example:

---
module test;

import std.traits   : isCallable;
version(all) version = my_version;

private bool onlyFuncs()
{
    bool result = true;
    foreach (member; __traits(allMembers, mixin(__MODULE__)))
    {
        static if (!is(mixin(member) == module) && !(is(mixin(member))))
        static if (__traits(getOverloads, mixin(__MODULE__), member,
true).length == 0)
        {
            pragma(msg, "`", member, "` ", "is not a type or a function");
            result = false;
            break;
        }
    }
    return result;
}
static assert(onlyFuncs());

void main(){}
---

Either custom version identifiers should be excluded from the traits results or
we should be able to
use them with a new variant of the isExpression, e.g `static if
(is(mixin(member) == version))`

--
Jun 09 2020