Bug 8716 – `package` restricts members usage in same module if there is no package name
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-09-23T22:17:00Z
Last change time
2016-04-11T09:41:00Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
verylonglogin.reg
Comments
Comment #0 by verylonglogin.reg — 2012-09-23T22:17:45Z
All asserts passes for e.g. `a.b` module name (except `C.init.sf()` which isn't evaluatable at CT now).
---
module ab;
package int gf() { return 0; }
static assert(gf() == 0); // function ab.gf is not accessible from module ab
class C // struct, class, or union
{
package:
enum e = 0;
immutable static int si = 0;
static int sf() { return 0; }
immutable int i = 0;
int f() const { return 0; }
}
static assert(C.e == 0);
static assert(C.si == 0);
static assert(C.sf() == 0); // function ab.C.sf is not accessible from module ab
static assert(C.i == 0);
static assert(C.init.e == 0);
static assert(C.init.si == 0); // undefined identifier 'si'
static assert(C.init.sf() == 0); // struct main.T!().C member sf is not accessible
static assert(C.init.i == 0);
---
Comment #1 by issues.dlang — 2012-09-23T22:57:26Z
I'm not sure that this is a bug, though the behavior is obviously surpising. Technically speaking, your module isn't _in_ a package, so naturally it won't have access to anything with package level access. For a module to be in a package, it needs to be explicitly put in one. e.g.
module x.y;
Without that first x., it's a module without a package, because there is no top-level package which holds modules which aren't explicitly put in a package.
Comment #2 by verylonglogin.reg — 2012-09-23T23:08:05Z
Of course, but it's common in D that there is no access restrictions in the same module at all.
Comment #3 by andrej.mitrovich — 2013-01-26T13:43:03Z