digitalmars.D.learn - Strange behaviour of __traits(allMembers)
- IchorDev (44/44) Jun 18 2023 `source/mod/submod.d:`
- FeepingCreature (4/7) Jun 18 2023 Yes, see also my bug report,
- IchorDev (3/10) Jun 18 2023 Whaaaaaaaaaaaaaaaaaaaaaat why has this not been fixed in the last
- FeepingCreature (8/19) Jun 18 2023 I think because nobody *needs* `__traits(allMembers)` of
- Dennis (2/4) Jun 28 2023 It's now fixed: https://github.com/dlang/dmd/pull/15335
- IchorDev (2/3) Jul 05 2023 Yesss! You're a hero indeed!
`source/mod/submod.d:`
```d
module mod.submod;
enum T1{ x }
```
`source/mod/package.d`:
```d
module mod;
import mod.submod;
enum T2{ y }
enum T3{ z }
static foreach(member; __traits(allMembers, mod)){
pragma(msg, member);
}
/**Prints:
object
T1
**/
```
I get the members of `mod.submod` instead of `mod`, even though I
supplied it with `mod`. The same happens if I use
`mixin(__MODULE__)`.
I've tested this using `dub` with the stock dub.json file (no
dependencies) with
- dmd 2.101.1
- dmd 2.104.0
- ldc2 1.30.0
- ldc2 1.32.2
- gdc 12.2.0
and I've gotten the same results for all of my tests every time.
If I change `mod.submod` to being a different module instead of a
submodule, `allMembers` lists the contents of `mod` as expected.
The members within the two modules don't seem to affect anything.
Importing `mod` from `mod.submod` makes it show up in
`allMembers`, meaning I can do `__traits(allMembers,
mod.mod.mod.mod.mod.` (etc.) recursively, and it still prints the
members of `mod.submod`. Putting `mod.submod` into `allMembers`
causes this error:
```
Error: undefined identifier `submod` in package `mod`
```
Does anyone understand why this happens?
Is there any way to subvert this behaviour, or is it actually a
bug?
Jun 18 2023
On Sunday, 18 June 2023 at 09:48:40 UTC, IchorDev wrote:Does anyone understand why this happens? Is there any way to subvert this behaviour, or is it actually a bug?Yes, see also my bug report, https://issues.dlang.org/show_bug.cgi?id=20008 "__traits(allMembers) of packages is complete nonsense".
Jun 18 2023
On Sunday, 18 June 2023 at 10:04:14 UTC, FeepingCreature wrote:On Sunday, 18 June 2023 at 09:48:40 UTC, IchorDev wrote:Whaaaaaaaaaaaaaaaaaaaaaat why has this not been fixed in the last 4 years!Does anyone understand why this happens? Is there any way to subvert this behaviour, or is it actually a bug?Yes, see also my bug report, https://issues.dlang.org/show_bug.cgi?id=20008 "__traits(allMembers) of packages is complete nonsense".
Jun 18 2023
On Sunday, 18 June 2023 at 10:21:16 UTC, IchorDev wrote:On Sunday, 18 June 2023 at 10:04:14 UTC, FeepingCreature wrote:I think because nobody *needs* `__traits(allMembers)` of packages. Mostly people just learn to skip them while scanning modules, and instead of iterating imports, they do the standard hack of "generate a list of all files in the project, string import it, and generate import statements for each". Yeah it's ugly. I guess the lesson is, nothing takes as long to fix as a bug with a well-known workaround.On Sunday, 18 June 2023 at 09:48:40 UTC, IchorDev wrote:Whaaaaaaaaaaaaaaaaaaaaaat why has this not been fixed in the last 4 years!Does anyone understand why this happens? Is there any way to subvert this behaviour, or is it actually a bug?Yes, see also my bug report, https://issues.dlang.org/show_bug.cgi?id=20008 "__traits(allMembers) of packages is complete nonsense".
Jun 18 2023
On Sunday, 18 June 2023 at 10:21:16 UTC, IchorDev wrote:Whaaaaaaaaaaaaaaaaaaaaaat why has this not been fixed in the last 4 years!It's now fixed: https://github.com/dlang/dmd/pull/15335
Jun 28 2023
On Wednesday, 28 June 2023 at 10:20:44 UTC, Dennis wrote:It's now fixed: https://github.com/dlang/dmd/pull/15335Yesss! You're a hero indeed!
Jul 05 2023









FeepingCreature <feepingcreature gmail.com> 