Example:
---
alias TemplateArgumentList(T...) = T;
struct S
{
alias T = TemplateArgumentList!(int, float);
}
pragma(msg, __traits(getProtection, __traits(getMember, S, "T")));
---
Output:
---
test.d(8): Error: argument int has no protection
false
---
getProtection's interface is simply poorly designed. As exemplified by the plethora of reports relating to it, it's tricky to use correctly, and as shown above, it fails to support all kinds of symbols. The latter means this is a bug, not an enhancement.
The interface should probably be:
__traits(getProtection, <aggregate>, <symbolName>)
Which should also succeed for inaccessible symbols. That way, both of getProtection's problems are solved.
Comment #1 by lultimouomo — 2014-12-19T22:25:22Z
On the same vein:
---
struct Template(string String) {
alias Alias = String;
}
pragma(msg, __traits(getProtection, __traits(getMember, Template!"string", "Alias")));
---
Output:
---
app.d(4): Error: argument "string" has no protection
false
---
And a bit different, but related:
---
struct Struct{};
struct Template(Type) {
private alias Alias = Type;
}
pragma(msg, __traits(getProtection, __traits(getMember, Template!Struct, "Alias")));
---
Output:
---
public
---
which does not seem right.
Going through getMember makes it impossible to get the protection attribute of member aliases.
Comment #2 by issues.dlang — 2023-11-17T01:50:47Z
This just came up in the learn newsgroup again:
---
struct bar {
public alias pubInt = int;
private alias privInt = int;
}
static foreach(member ; __traits(allMembers, bar)) {
// Error: argument `int` has no visibility
pragma(msg, __traits(getVisibility, __traits(getMember, bar, member)));
}
---
I would guess that the core problem here is that the alias gets replaced with what it's an alias to before getVisibility actually operates on it, which is obviously the wrong order to do things in.
Comment #3 by robert.schadek — 2024-12-13T18:18:18Z