Bug 15907 – Unjustified "is not visible from module" deprecation warning when using getMember trait

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2016-04-09T22:01:00Z
Last change time
2016-11-04T09:05:01Z
Keywords
industry
Assigned to
code
Creator
m.bierlee

Comments

Comment #0 by m.bierlee — 2016-04-09T22:01:26Z
Some libraries use the "allMembers" trait to get access to all members of an instance, including private members. The change "Import access checks for fully qualified names were fixed.", introduced in DMD 2.071.0, now shows a deprecation warning in cases where the library module accesses members of classes (and structs, probably) which were not imported in that module. Consider the following code: ------------------------------ module app; import library; class FirstClass {} class SecondClass { private FirstClass firstClass; } void main() { auto manipulator= new PrivateMemberManipulator(); auto instance = new SecondClass(); manipulator.process!SecondClass(instance); } ------------------------------ module library; import std.traits; class PrivateMemberManipulator { public void process(Type)(Type instance) { foreach (member ; __traits(allMembers, Type)) { static if (__traits(getProtection, __traits(getMember, instance, member)) == "private") { // Do things } } } } ----------------------------- When compiled, the following deprecation warning is shown: src\library.d(8,39): Deprecation: app.SecondClass.firstClass is not visible from module library This is because the results of "allMembers" are fully qualified (as they should be). I feel this usage is perfectly legal as there is no way a library can (or should) import all application classes.
Comment #1 by m.bierlee — 2016-04-09T22:09:45Z
I forgot to add that it's actually "getMember" which causes the deprecation warning and "allMembers" is not fully qualified.
Comment #2 by me — 2016-04-24T14:21:14Z
Just ran into this issue as well - are there any "decent" workarounds? All I've found is manually excluding the problem objects before using getMember, but that's not really a scalable fix.
Comment #3 by acehreli — 2016-07-26T22:36:47Z
Here is another case with two modules (and with a WORKAROUND): // ----- a.d: mixin template MyMixin(alias MODULE) { shared static this() { initFunc!(mixin(MODULE))(); } } void initFunc(alias MODULE)() { foreach (member; __traits(allMembers, MODULE)) { static if(__traits(hasMember, __traits(getMember, MODULE, member), "someProperty")) { } } } // ----- b.d: import a; mixin MyMixin!__MODULE__; void main() { } getMember inside a.d causes the following warnings: a.d(9): Deprecation: b.object is not visible from module a a.d(9): Deprecation: b.a is not visible from module a Here is a WORKAROUND. Make the following changes in a.d: 1) Convert initFunc to a mixin template 2) Mix it in where it's called 3) Call it after it's mixed in mixin template MyMixin(alias MODULE) { shared static this() { mixin initFunc!(mixin(MODULE)); // (2) initFunc(); // (3) } } mixin template initFunc(alias MODULE) { // (1) void initFunc() { foreach (member; __traits(allMembers, MODULE)) { static if(__traits(hasMember, __traits(getMember, MODULE, member), "someProperty")) { } } } } Ali
Comment #4 by code — 2016-08-24T17:42:25Z
*** Issue 15877 has been marked as a duplicate of this issue. ***
Comment #5 by github-bugzilla — 2016-08-29T17:03:58Z
Commits pushed to stable at https://github.com/dlang/dlang.org https://github.com/dlang/dlang.org/commit/deb87b753a455ae847389642d2835a9fb891ab5a spec change and changelog entry for Issue 15907 https://github.com/dlang/dlang.org/commit/2ecabf0dab63dcdb935af859093ffc05b366c3ec Merge pull request #1444 from MartinNowak/fix15907 spec change and changelog entry for Issue 15907
Comment #6 by github-bugzilla — 2016-08-29T17:05:32Z
Commits pushed to stable at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/b2d0226d4845d69b60ea26f54c1edec36ad08b11 supplemental change for Issue 15907 fix - change of __traits(allMembers) semantics cause getSymbolsByUDA to no longer return invisible (private) symbols - add test for using getSymbolsByUDA as mixin template to still access private symbols https://github.com/dlang/phobos/commit/d10780f19544f73907540e98aeee0039807e4578 Merge pull request #4747 from MartinNowak/fix15907 supplemental change for Issue 15907 fix
Comment #7 by github-bugzilla — 2016-08-29T17:36:36Z
Commits pushed to stable at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/f899b4b59620e354b6ba0acfe843efb559202cd8 fix Issue 15907 - unjustified deprecation with getMember - fixed by changing the semantics of allMembers and derivedMembers to respect visibility - even though the private members were listed before, they haven't been accessible - it's possible to mixin a template in order to use it with private symbols (example given in changelog) - fixed ice10598 test b/c it was relying on the presence of the private object import https://github.com/dlang/dmd/commit/49cb97213303c902844b7189ced1cf8833214437 Merge pull request #6078 from MartinNowak/fix15907 fix Issue 15907 - unjustified deprecation with getMember
Comment #8 by github-bugzilla — 2016-08-30T19:33:05Z
Comment #9 by github-bugzilla — 2016-09-10T02:54:54Z
Commits pushed to stable at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/101d65993abc868490876883a17b1ba81c04fe19 fix Issue 15907 - unjustified deprecation with getMember - skip visibility checks for hasMember, getMember, and getOverloads - inherit scope flags for the new SCOPEflag and noaccesscheck - keep existing access checks for now https://github.com/dlang/dmd/commit/6b285369a9b17216244dfdf8f38fbc48ed38dc53 Merge pull request #6111 from MartinNowak/fix15907 fix Issue 15907 - unjustified deprecation with getMember
Comment #10 by github-bugzilla — 2016-09-14T09:51:08Z
Comment #11 by github-bugzilla — 2016-09-19T23:46:58Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/f899b4b59620e354b6ba0acfe843efb559202cd8 fix Issue 15907 - unjustified deprecation with getMember https://github.com/dlang/dmd/commit/49cb97213303c902844b7189ced1cf8833214437 Merge pull request #6078 from MartinNowak/fix15907 https://github.com/dlang/dmd/commit/101d65993abc868490876883a17b1ba81c04fe19 fix Issue 15907 - unjustified deprecation with getMember https://github.com/dlang/dmd/commit/6b285369a9b17216244dfdf8f38fbc48ed38dc53 Merge pull request #6111 from MartinNowak/fix15907
Comment #12 by github-bugzilla — 2016-11-04T09:05:01Z
Commits pushed to newCTFE at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/f899b4b59620e354b6ba0acfe843efb559202cd8 fix Issue 15907 - unjustified deprecation with getMember https://github.com/dlang/dmd/commit/49cb97213303c902844b7189ced1cf8833214437 Merge pull request #6078 from MartinNowak/fix15907 https://github.com/dlang/dmd/commit/101d65993abc868490876883a17b1ba81c04fe19 fix Issue 15907 - unjustified deprecation with getMember https://github.com/dlang/dmd/commit/6b285369a9b17216244dfdf8f38fbc48ed38dc53 Merge pull request #6111 from MartinNowak/fix15907