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).
Comment #2 by k.hara.pg — 2013-07-19T01:09:14Z
Comment #3 by github-bugzilla — 2013-07-21T13:15:50Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/ad28224b3c5240f466c8e3b384a55b07742a4a90 fix Issue 9546 - getProtection trait does not work with mixin or getMember Stop access check during `__traits(getProtection)` evaluated. https://github.com/D-Programming-Language/dmd/commit/2ead3f00168ce9b99e1c845e631b3603bcccb905 Merge pull request #2361 from 9rnsr/fix9546 Issue 9546 - getProtection trait does not work with mixin or getMember