Package visibility strange behaviour

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Feb 27 09:59:52 PST 2017


On Monday, February 27, 2017 14:07:21 Oleg B via Digitalmars-d-learn wrote:
> Hello. Is this behavior normal, or it's a bug? And if it's normal
> why it's normal? I want to use function with `package` visibility
> in same package where it's defined, but I don't.
>
> ```d
> module package_visible;
> package void foo() { }
> void main() { foo(); }
> ```
>
> ```
> % rdmd package_visible.d
> package_visible.d(3): Error: function package_visible.foo is not
> accessible from module package_visible
> Failed: ["dmd", "-v", "-o-", "package_visible.d", "-I."]
> ```
>
> dmd version v2.073.1

In your example, your module isn't in a package. It's at the top-level. So,
package doesn't work, becasue there's no package. In this case, you'd just
use private. Presumably, in any actual code, you would have a package rather
than putting the module at the top level, and then it would work.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list