Bug 9546 – getProtection trait does not work with mixin or getMember
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-02-19T20:37:00Z
Last change time
2013-07-21T13:16:03Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
andrej.mitrovich
Comments
Comment #0 by andrej.mitrovich — 2013-02-19T20:37:50Z
/imorts/a.d:
---------------------------
module imports.a;
class S
{
private int privA;
protected int protA;
package int packA;
}
---------------------------
/test.d:
---------------------------
import imports.a;
void main()
{
S s;
static assert(__traits(getProtection, s.privA) == "private");
static assert(__traits(getProtection, s.protA) == "protected");
static assert(__traits(getProtection, s.packA) == "package");
/** NG - symbols not accessible */
static assert(__traits(getProtection, mixin("s.privA")) == "private");
static assert(__traits(getProtection, mixin("s.protA")) == "protected");
static assert(__traits(getProtection, mixin("s.packA")) == "package");
/** NG - symbols not accessible */
static assert(__traits(getProtection,
__traits(getMember, s, "privA")) == "private");
static assert(__traits(getProtection,
__traits(getMember, s, "protA")) == "protected");
static assert(__traits(getProtection,
__traits(getMember, s, "packA")) == "package");
}
---------------------------
Comment #1 by andrej.mitrovich — 2013-02-19T21:12:30Z
An almost working workaround is to use T.init.tupleof[index] to get a member without triggering access protection errors, however this will not work with methods since they're not part of .tupleof() (only fields are).