file1.d ---
import std.stdio;
file2.d ---
import file1;
pragma(msg, __traits(getProtection, __traits(getMember, file1, "std")));
pragma(msg, __traits(getProtection, file1.std));
static assert( __traits(isSame, __traits(getMember, file1, "std"), file1.std));
output:
public
private
instead of
private
private
Bug seems to happen only for packages.
Comment #1 by razvan.nitu1305 — 2018-09-28T13:10:33Z
The matter of fact is that `__traits(getMember, file1, "std")` sees file1.std as a package, while getProtection sees file1.std as an import. `__traits(isSame)` compares them equally because [1] made it smart enough to compare them.
The situation is a bit complicated because you cannot identify imports by their first package. Consider this example:
//file1.d
public import std.stdio;
private import std.traits;
//file2.d
pragma(msg, __traits(getProtection, file1.std));
The invocation in file2 is ambiguous in this situation. However, if getProtection would consider file.std as a package and not an import it would pretty much become useless because the module itself is always public. I think that we need to come up with a way of identifying imports.
[1] https://github.com/dlang/dmd/pull/7095/files
Comment #2 by robert.schadek — 2024-12-13T19:00:09Z