www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15907] New: Unjustified "is not visible from module"


          Issue ID: 15907
           Summary: Unjustified "is not visible from module" deprecation
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: regression
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: m.bierlee 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();

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

I feel this usage is perfectly legal as there is no way a library can (or
should) import all application classes.

Apr 09 2016