www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Are selective imports supposed to always be public?

reply tsbockman <thomas.bockman gmail.com> writes:
Why does this code compile? Shouldn't the `isIntegral` import be 
private to module `testB` unless I explicitly ask for it to be 
public?

// testB.d
module testB;

import std.traits : isIntegral;

// testA.d
module testA;

void main(string[] args) {
     import testB;
     static assert(isIntegral!int);
}
Dec 06 2015
parent reply Mike Parker <aldacron gmail.com> writes:
On Sunday, 6 December 2015 at 10:31:58 UTC, tsbockman wrote:
 Why does this code compile? Shouldn't the `isIntegral` import 
 be private to module `testB` unless I explicitly ask for it to 
 be public?

 // testB.d
 module testB;

 import std.traits : isIntegral;

 // testA.d
 module testA;

 void main(string[] args) {
     import testB;
     static assert(isIntegral!int);
 }
A very old bug. https://issues.dlang.org/show_bug.cgi?id=314
Dec 06 2015
next sibling parent tsbockman <thomas.bockman gmail.com> writes:
On Sunday, 6 December 2015 at 11:10:44 UTC, Mike Parker wrote:
 A very old bug.

 https://issues.dlang.org/show_bug.cgi?id=314
Wow! 2006. Looks like it might get fixed soon, though: https://github.com/D-Programming-Language/dmd/pull/3407
Dec 06 2015
prev sibling parent Jonathan M Davis via Digitalmars-d-learn writes:
On Sunday, December 06, 2015 11:10:44 Mike Parker via Digitalmars-d-learn wrote:
 On Sunday, 6 December 2015 at 10:31:58 UTC, tsbockman wrote:
 Why does this code compile? Shouldn't the `isIntegral` import
 be private to module `testB` unless I explicitly ask for it to
 be public?

 // testB.d
 module testB;

 import std.traits : isIntegral;

 // testA.d
 module testA;

 void main(string[] args) {
     import testB;
     static assert(isIntegral!int);
 }
A very old bug. https://issues.dlang.org/show_bug.cgi?id=314
Yeah. At this point, you should basically never use selective imports at the module-level. As I understand it, work has been done towards fixing this bug and some related bugs recently, but the compiler devs aren't in agreement on the changes. So, for the moment at least, the bug continues to be a problem, but there's a good chance that it'll get fixed semi-soon. - Jonathan M Davis
Dec 06 2015