Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Imported package have different protection depending on how it's accessed #19474

Open
dlangBugzillaToGithub opened this issue Aug 6, 2018 · 1 comment

Comments

@dlangBugzillaToGithub
Copy link

basile-z reported this on 2018-08-06T08:58:46Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=19144

CC List

  • RazvanN

Description

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.
@dlangBugzillaToGithub
Copy link
Author

razvan.nitu1305 commented on 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant