D-Programming-Language/dmd — pull request #3651 by Dicebot (2014-06-08 15:34:20+00:00)
Title: Fix #2529: explicit protection package

https://issues.dlang.org/show_bug.cgi?id=2529

This does not implement original proposal from linked bugzilla entry but addresses same goal.

Currently there is no way to use `package` protection attribute with deeply nested package hierarchy, forcing to either use flat one or `public` protection. This is one of blocking issues for further usage of `package.d` in Phobos and one of reasons why namespace hacks are so popular.

For example, if helpers in `std.internal` will be marked as `package`, only `std.internal` will be able to access those, but not rest of `std`. This PR fixes it by allowing `package()` syntax to explicitly define owning package.

This new syntax will work:

```D
module std.internal.mod1;
package(std) void foo() {}
```

```D
module std.mod2;
import std.internal.mod2;
void bar() { foo(); }
```

Exact semantics can are described by added "protection" tests to `test/compilable` (last commit in this PR).

Plain `package` behavior is unchanged and thus no breaking changes introduced.