www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8716] New: `package` restricts members usage in same module if there is no package name

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8716

           Summary: `package` restricts members usage in same module if
                    there is no package name
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: verylonglogin.reg gmail.com



09:17:45 MSD ---
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);
---

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 23 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8716


Jonathan M Davis <jmdavisProg gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg gmx.com



PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 23 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8716




10:08:05 MSD ---
Of course, but it's common in D that there is no access restrictions in the
same module at all.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 23 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8716


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull
                 CC|                            |andrej.mitrovich gmail.com
         AssignedTo|nobody puremagic.com        |andrej.mitrovich gmail.com



13:43:03 PST ---
https://github.com/D-Programming-Language/dmd/pull/1556

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 26 2013