[Issue 1297] New: Static modules, aka enforcing static import.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jun 28 12:52:06 PDT 2007


http://d.puremagic.com/issues/show_bug.cgi?id=1297

           Summary: Static modules, aka enforcing static import.
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: spec
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: ibisbasenji at gmail.com


I find myself using the very nice static-renaming-import scheme to provide
namespacing capability.  For example, rather than have a module full of
database functions with, for example, a 'db_' prefix to avoid collisions, its
useful to just use 'static import Db = foo.bar.Db;' and call all functions via
'Db.func()'.

Since some modules are tailored toward use in this way, I feel it would be nice
to have a way to specifically enforce our module being static-imported.  The
proposal is simple enough: allow the 'static' attribute on 'module'
declerations, with the meaning that any corresponding 'import' must also be
'static'.  Example:

-----[ foo/bar/Db.d ]-----
static module foo.bar.Db;

void func () {}

-----[ fred.d ]-----
import foo.bar.Db; // <- Error: import for module 'foo.bar.Db' must be static

-----[ greg.d ]-----
static import foo.bar.Db; // <- Ok


Naturally, static-modules should still play nice with renaming imports and
selective imports.


-- 



More information about the Digitalmars-d-bugs mailing list