D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 20915 - __traits(allMembers) results include custom version identifiers, which is unusable
Summary: __traits(allMembers) results include custom version identifiers, which is unu...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 major
Assignee: No Owner
URL: https://forum.dlang.org/post/xnjziupy...
Keywords: pull
Depends on:
Blocks:
 
Reported: 2020-06-09 17:45 UTC by basile-z
Modified: 2021-04-09 10:29 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description basile-z 2020-06-09 17:45:38 UTC
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))`
Comment 1 Stanislav Blinov 2020-06-09 18:05:32 UTC
Instead of

static if (!is(mixin(member) == module) && !(is(mixin(member))))

use

static if (is(typeof(mixin(member))))
Comment 2 basile-z 2020-06-09 18:13:46 UTC
thanks Stanislav, that fixes the problem I encountered in particular.

Generally speaking the issue is still valid. There's no way to detect that a member is a version identifier so using it this way:

   mixin("version(", member, ")");

is not possible.
Comment 3 Dlang Bot 2020-06-10 02:09:02 UTC
@NilsLankila created dlang/dmd pull request #11255 "fix issue 20915 - add support for `is(identifier == version)`" fixing this issue:

- fix issue 20915 - add support for `is(identifier == version)`
  
  This fills the small gap that existed because `__traits(allMembers)` could return the identifiers of the `VersionSymbol`s defined in the source but there was no way to identify them as such.

https://github.com/dlang/dmd/pull/11255
Comment 4 Walter Bright 2020-06-10 22:53:27 UTC
__traits(allMembers) shouldn't be picking up version identifiers.
Comment 5 Dlang Bot 2020-06-10 23:33:14 UTC
@NilsLankila created dlang/dmd pull request #11260 "fix issue 20915 - exclude version and debug identifier from `__traits(allMembers)` results" fixing this issue:

- fix issue 20915 - exclude version and debug identifier from `__traits(allMembers)` results

https://github.com/dlang/dmd/pull/11260
Comment 6 Dlang Bot 2020-06-11 08:40:19 UTC
dlang/dmd pull request #11260 "fix issue 20915 - exclude version and debug identifier from `__traits(allMembers)` results" was merged into master:

- fba63812c40ba01ff0c1fd09a238233a9eff9a90 by Nils Lankila:
  fix issue 20915 - exclude version and debug identifier from `__traits(allMembers)` results

https://github.com/dlang/dmd/pull/11260
Comment 7 Dlang Bot 2021-04-09 10:29:21 UTC
dlang/dmd pull request #12411 "[dmd-cxx] fix Issue 21813 - [REG-master] Bootstrap broken from dmd-cxx baseline" was merged into dmd-cxx:

- 6dc21d3fcbee214b8aa73b707ad0e16236425c2c by Nils Lankila:
  [dmd-cxx] fix issue 20915 - exclude version and debug identifier from  results

https://github.com/dlang/dmd/pull/12411