[dmd-internals] I think it's time to fix bug 314

Don Clugston dclugston at googlemail.com
Thu Aug 12 06:18:56 PDT 2010


Bug 314 [module] Static, renamed, and selective imports are always public

It is a serious hole in the module system. It has had a patch for two years;
it has twice as many votes as anything else in Bugzilla. It's also had
two years of testing in LDC.
I think it's time to kill it.

I've reviewed the patch, and apart from a minor issue which I've fixed
(it couldn't compile object_.d), it seems to be good.
Applying it showed up bugs in druntime, and Phobos. This is a good
sign. I've checked in fixes for those bugs.
There's also a bug in the test suite: test24 should import std.string.

-----
To increase the chance of action on this, I repeat the patch here.
Because there are changes to a several places in import.c, I've attached it.
There are only really a couple of lines which change. Same file applies to D1.
The changes to the other two files are listed below.

Add these members to struct Import {} in import.h:

    enum PROT protection;
    enum PROT prot();

Add these three lines to dsymbol.c, line 757.

Dsymbol *ScopeDsymbol::search(Loc loc, Identifier *ident, int flags)
{
    //printf("%s->ScopeDsymbol::search(ident='%s', flags=x%x)\n",
toChars(), ident->toChars(), flags);
    //if (strcmp(ident->toChars(),"c") == 0) *(char*)0=0;

    // Look in symbols declared in this module
    Dsymbol *s = symtab ? symtab->lookup(ident) : NULL;
    //printf("\ts = %p, imports = %p, %d\n", s, imports, imports ?
imports->dim : 0);

+    // hide private nonlocal symbols
+    if (flags & 1 && s && s->prot() == PROTprivate)
+        s = NULL;

    if (s)
    {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: import.c
Type: application/octet-stream
Size: 10153 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/dmd-internals/attachments/20100812/c85881f3/attachment.obj>


More information about the dmd-internals mailing list