Bug 20915 – __traits(allMembers) results include custom version identifiers, which is unusable
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-06-09T17:45:38Z
Last change time
2021-04-09T10:29:21Z
Keywords
pull
Assigned to
No Owner
Creator
Basile-z
Comments
Comment #0 by b2.temp — 2020-06-09T17:45:38Z
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 by stanislav.blinov — 2020-06-09T18:05:32Z
Instead of
static if (!is(mixin(member) == module) && !(is(mixin(member))))
use
static if (is(typeof(mixin(member))))
Comment #2 by b2.temp — 2020-06-09T18:13:46Z
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 by dlang-bot — 2020-06-10T02:09:02Z
@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 by bugzilla — 2020-06-10T22:53:27Z
__traits(allMembers) shouldn't be picking up version identifiers.
Comment #5 by dlang-bot — 2020-06-10T23:33:14Z
@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 by dlang-bot — 2020-06-11T08:40:19Z
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 by dlang-bot — 2021-04-09T10:29:21Z
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