[Issue 15907] Unjustified "is not visible from module" deprecation warning when using getMember trait

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Jul 26 15:36:47 PDT 2016


https://issues.dlang.org/show_bug.cgi?id=15907

Ali Cehreli <acehreli at yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |acehreli at yahoo.com

--- Comment #3 from Ali Cehreli <acehreli at yahoo.com> ---
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

--


More information about the Digitalmars-d-bugs mailing list