[Issue 15907] New: Unjustified "is not visible from module" deprecation warning
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sat Apr 9 15:01:26 PDT 2016
https://issues.dlang.org/show_bug.cgi?id=15907
Issue ID: 15907
Summary: Unjustified "is not visible from module" deprecation
warning
Product: D
Version: D2
Hardware: x86_64
OS: Windows
Status: NEW
Severity: regression
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: m.bierlee at lostmoment.com
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.
--
More information about the Digitalmars-d-bugs
mailing list