Non-static foreach on tupleof has no UDAs?

IchorDev zxinsworld at gmail.com
Thu Jul 31 11:29:41 UTC 2025


How come doing a `foreach` on `.tupleof` causes `
__traits(getAttributes` to return nothing? Is it because it 
creates a new 'symbol'? Is this a bug?
```d
struct y{
	int z;
}

struct X{
	@y(z: 10) string x;
}

void main(){
	X a;
	foreach(b; a.tupleof){
		pragma(msg, __traits(getAttributes, b)); //AliasSeq!()
	}
}
```
Changing it to a `static foreach` prints `AliasSeq!(y(10))` as 
expected, but now I can't use `b` in runtime code. Obviously 
there's a workaround, but it's ugly. I'd much prefer if the above 
code worked rather than having to do this:
```d
static foreach(i; 0..a.tupleof.length){
	pragma(msg, __traits(getAttributes, a.tupleof[i])); 
//AliasSeq!(y(10))
}
```


More information about the Digitalmars-d-learn mailing list