Bug 10111 – getProtection trait should work with inaccessible fields
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-05-17T17:30:00Z
Last change time
2013-05-17T17:42:10Z
Keywords
rejects-valid
Assigned to
nobody
Creator
andrej.mitrovich
Comments
Comment #0 by andrej.mitrovich — 2013-05-17T17:30:56Z
-----
module foo;
struct S
{
private void m() { }
}
-----
-----
module test;
import foo;
void main()
{
static if (__traits(getProtection, S.m != "private"))
{
// field might be accessible
}
}
-----
$ dmd test.d
> test.d(7): Error: struct foo.S member m is not accessible
There's not much point in having this trait if it fails to compile due to accessibility problems. The trait has only one purpose and it's to return a string representation of a symbol's protection. There's nothing damaging about allowing it access to all fields, so I think the above should work.
Comment #1 by wazar.leollone — 2013-05-17T17:35:58Z
is this bug is regression?
You was created an another issue: http://d.puremagic.com/issues/show_bug.cgi?id=9546
In #9546 same tests was passed.
>static assert(__traits(getProtection, s.privA) == "private");
>static assert(__traits(getProtection, s.protA) == "protected");
>static assert(__traits(getProtection, s.packA) == "package");
Comment #2 by andrej.mitrovich — 2013-05-17T17:42:10Z
God what a silly typo:
static if (__traits(getProtection, S.m != "private"))
The parenthesis is wrong, it should be:
static if (__traits(getProtection, S.m) != "private")