Bug 19144 – Imported package have different protection depending on how it's accessed

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-08-06T08:58:46Z
Last change time
2024-12-13T19:00:09Z
Assigned to
No Owner
Creator
basile-z
Moved to GitHub: dmd#19474 →

Comments

Comment #0 by b2.temp — 2018-08-06T08:58:46Z
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
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19474 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB