digitalmars.D.bugs - [Issue 314] New: Static, renamed, and selective imports are always public
- d-bugmail puremagic.com Aug 27 2006
- d-bugmail puremagic.com Jan 23 2007
- d-bugmail puremagic.com Jan 28 2007
- d-bugmail puremagic.com Apr 16 2008
- d-bugmail puremagic.com Apr 17 2008
- d-bugmail puremagic.com Sep 02 2008
- d-bugmail puremagic.com May 12 2009
- d-bugmail puremagic.com May 12 2009
- d-bugmail puremagic.com May 13 2009
- d-bugmail puremagic.com May 16 2009
- d-bugmail puremagic.com Aug 20 2009
- d-bugmail puremagic.com Aug 31 2009
- d-bugmail puremagic.com May 07 2010
- d-bugmail puremagic.com May 07 2010
- d-bugmail puremagic.com May 26 2010
- d-bugmail puremagic.com May 26 2010
- d-bugmail puremagic.com May 26 2010
- d-bugmail puremagic.com May 26 2010
- d-bugmail puremagic.com Aug 11 2010
- d-bugmail puremagic.com Aug 11 2010
- d-bugmail puremagic.com Aug 12 2010
- d-bugmail puremagic.com Aug 12 2010
- d-bugmail puremagic.com Aug 12 2010
- d-bugmail puremagic.com Aug 12 2010
- d-bugmail puremagic.com Aug 12 2010
- d-bugmail puremagic.com Aug 12 2010
- d-bugmail puremagic.com Aug 12 2010
- d-bugmail puremagic.com Aug 19 2010
- d-bugmail puremagic.com Aug 20 2010
- d-bugmail puremagic.com Oct 28 2010
- d-bugmail puremagic.com Nov 03 2010
- d-bugmail puremagic.com Nov 03 2010
- d-bugmail puremagic.com May 29 2011
http://d.puremagic.com/issues/show_bug.cgi?id=314 Summary: Static, renamed, and selective imports are always public Product: D Version: 0.165 Platform: PC OS/Version: Windows Status: NEW Keywords: accepts-invalid Severity: major Priority: P2 Component: DMD AssignedTo: bugzilla digitalmars.com ReportedBy: deewiant gmail.com BugsThisDependsOn: 313 In file a.d: -- // explicit privates unnecessary but added for clarity version(stat) private static import std.stdio; version(rena) private import io = std.stdio; version(sele) private import std.stdio : writefln; -- In file b.d: -- import a; void main() { version(stat) std.stdio.writefln("This should not work."); version(rena) io.writefln("This should not work."); version(sele) writefln("This should not work."); } -- Compiled with version=stat, version=rena, or version=sele, the program outputs "This should not work.", when it shouldn't even compile. Note that the version(stat) case is dependant on Issue 313. --
Aug 27 2006
http://d.puremagic.com/issues/show_bug.cgi?id=314 ------- Comment #1 from davidl 126.com 2007-01-23 04:30 ------- errr, d 1.0 still has this bug.. but bug 313's example doesn't work any more. --
Jan 23 2007
http://d.puremagic.com/issues/show_bug.cgi?id=314 torhu yahoo.com changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |wbaxter gmail.com ------- Comment #2 from torhu yahoo.com 2007-01-29 01:56 ------- *** Bug 604 has been marked as a duplicate of this bug. *** --
Jan 28 2007
http://d.puremagic.com/issues/show_bug.cgi?id=314 ------- Comment #3 from kamm-removethis incasoftware.de 2008-04-16 14:29 ------- Created an attachment (id=246) --> (http://d.puremagic.com/issues/attachment.cgi?id=246&action=view) Fix by checking protection attribute for all nonlocal symbols The patch has been tested rudimentarily on llvmdc. I have commented the two crucial changes. Even if there is a good reason for not checking the protection attribute of all symbols, it should still be simple to special case this fix for import declarations and the alias declarations generated by them. Note that module c; int var; -- module b; import c; -- module a; import b; void main { var = 1; // var: undefined identifier (no change) c.var = 1; // c: undefined identifier (instead of ok) b.c.var = 1; // still ok } --
Apr 16 2008
http://d.puremagic.com/issues/show_bug.cgi?id=314 ------- Comment #4 from kamm-removethis incasoftware.de 2008-04-17 15:26 ------- (In reply to comment #3)Created an attachment Fix by checking protection attribute for all nonlocal symbols
I aimed a little high; this patch does not add checks for the protection attribute for all nonlocal symbols. It adds checks only for the ones contained in ScopeDsymbol and only in a coarse (public or private) way. But doing that consistently is a different bug/enhancement anyway. Using a variation of this patch to fix the import issue bugs 313 and 314 describe should still be fine. --
Apr 17 2008
http://d.puremagic.com/issues/show_bug.cgi?id=314 jarrett.billingsley gmail.com changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |sean invisibleduck.org ------- Comment #5 from jarrett.billingsley gmail.com 2008-09-02 22:17 ------- *** Bug 2330 has been marked as a duplicate of this bug. *** --
Sep 02 2008
http://d.puremagic.com/issues/show_bug.cgi?id=314 Christian Kamm <kamm-removethis incasoftware.de> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #246 is|0 |1 obsolete| | --- Comment #6 from Christian Kamm <kamm-removethis incasoftware.de> 2009-05-12 11:22:49 PDT --- Created an attachment (id=364) --> (http://d.puremagic.com/issues/attachment.cgi?id=364) patch Ignores nonlocal private symbols when looking up and identifier. Sets the protection attribute of imports and generated aliases to the protection level specified for the import. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 12 2009
http://d.puremagic.com/issues/show_bug.cgi?id=314 --- Comment #7 from Walter Bright <bugzilla digitalmars.com> 2009-05-12 19:04:58 PDT --- Access protection is defined to happen after lookup and overload resolution. Making private symbols invisible defeats this, and also doesn't work as the overload list is a linked list, and making the head of it private would hide the rest of the possibly public overloads. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 12 2009
http://d.puremagic.com/issues/show_bug.cgi?id=314 --- Comment #8 from Christian Kamm <kamm-removethis incasoftware.de> 2009-05-13 10:45:04 PDT --- Thanks for the thorough reply. I disagree that overload resolution happens strictly before access checks. Consider: a.d -- void foo(int) { printf("foo-i"); } b.d -- import a : foo; void foo(float) { printf("foo-f"); } c.d -- import b; void main() { int i; foo(i); } Like this, with dmd 1.043, you get "foo-i". If you remove the selective import of foo, you get "foo-f". Private imports are invisible at lookup-time, but renamed or selective private imports aren't. Therefore it seems to me that making these invisible is the right thing to do. The patch does have a problem with overloads though and that ought to be fixed. Would you accept a patch that works along the same lines but handles overloads correctly? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 13 2009
http://d.puremagic.com/issues/show_bug.cgi?id=314 --- Comment #9 from Christian Kamm <kamm-removethis incasoftware.de> 2009-05-16 05:54:34 PDT --- I've updated the patch. Treating overloads correctly complicated the issue quite a bit. What I've done is to store the import protection in the AliasDeclarations and FuncAliasDeclarations generated by selective and renamed imports. These are then ignored when traversing the overload tree if they are in a different module than the one initiating the traversal. That means, however, that overload resolution needs to know which module is triggering it and has led to a lot of module passing. :/ I've also made the hiding of private symbols in ScopeDsymbol::search specific to AliasDeclarations generated by ImportStatement. Making the protection attributes apply consistently to more than Func- and VarDecls is a separate issue. The LDC changesets are: http://www.dsource.org/projects/ldc/changeset/1358 http://www.dsource.org/projects/ldc/changeset/1362 I can make a patch against DMD if requested. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 16 2009
http://d.puremagic.com/issues/show_bug.cgi?id=314 Stewart Gordon <smjg iname.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |smjg iname.com --- Comment #10 from Stewart Gordon <smjg iname.com> 2009-08-20 11:57:14 PDT --- (In reply to comment #7)Access protection is defined to happen after lookup and overload resolution.
Defined where in the spec?Making private symbols invisible defeats this,
Would it be reasonable to change it as I described in the final paragraph of issue 3254 comment 3?and also doesn't work as the overload list is a linked list, and making the head of it private would hide the rest of the possibly public overloads.
That's obviously an implementation issue. Possible ways to deal with this: (a) have multiple linked lists, one for each protection attribute (b) build the linked list in such a way that the head element will always be one of the ones of the most public access level that exists among the overloads -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 20 2009
http://d.puremagic.com/issues/show_bug.cgi?id=314 Matti Niemenmaa <matti.niemenmaa+dbugzilla iki.fi> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |2korden gmail.com --- Comment #11 from Matti Niemenmaa <matti.niemenmaa+dbugzilla iki.fi> 2009-08-31 11:56:41 PDT --- *** Issue 3275 has been marked as a duplicate of this issue. *** -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 31 2009
http://d.puremagic.com/issues/show_bug.cgi?id=314 nfxjfg gmail.com changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |nfxjfg gmail.com --- Comment #12 from nfxjfg gmail.com 2010-05-07 02:14:37 PDT --- Whenever I compile some code in ldc, that has been developed with dmd, I get compilation errors related to this bug. That's because ldc (at least partially) fixed it. As far as I can tell, ldc never rejected actually valid code related to this bug. It's a bit ridiculous. What keeps back the patches going into dmd? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 07 2010
http://d.puremagic.com/issues/show_bug.cgi?id=314 Tomas Lindquist Olsen <tomas famolsen.dk> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |tomas famolsen.dk --- Comment #13 from Tomas Lindquist Olsen <tomas famolsen.dk> 2010-05-07 02:42:38 PDT --- stubbornness ? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 07 2010
http://d.puremagic.com/issues/show_bug.cgi?id=314 Trass3r <mrmocool gmx.de> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |mrmocool gmx.de --- Comment #14 from Trass3r <mrmocool gmx.de> 2010-05-26 15:10:04 PDT --- when will this be fixed? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 26 2010
http://d.puremagic.com/issues/show_bug.cgi?id=314 --- Comment #15 from Leandro Lucarella <llucax gmail.com> 2010-05-26 15:19:42 PDT --- In D4, maybe =P Don't be impatient, is just number 1 in votes! -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 26 2010
http://d.puremagic.com/issues/show_bug.cgi?id=314 --- Comment #16 from Trass3r <mrmocool gmx.de> 2010-05-26 15:42:36 PDT --- Well that's the point. - 32 votes! - present since v0.165! - patch is available that seems to work for ldc -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 26 2010
http://d.puremagic.com/issues/show_bug.cgi?id=314 --- Comment #17 from Leandro Lucarella <llucax gmail.com> 2010-05-26 19:01:01 PDT --- I was being sarcastic =) -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 26 2010
http://d.puremagic.com/issues/show_bug.cgi?id=314 Don <clugdbug yahoo.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |clugdbug yahoo.com.au --- Comment #18 from Don <clugdbug yahoo.com.au> 2010-08-11 12:48:59 PDT --- I have tried this patch on the latest D2. I've found two problems with it: (1) object needs special treatment, it must not default to private. (2) It completely fails for selective imports. The first issue is trivial to fix; the main patch in import.c becomes: void Import::importAll(Scope *sc) { if (!mod) { load(sc); mod->importAll(0); + /* Default to private importing, except for object. + */ + if (id != Id::object) { + protection = sc->protection; + if (!sc->explicitProtection) + protection = PROTprivate; + } OTOH applying the patch has shown up several bugs in druntime and in the compiler test suite. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 11 2010
http://d.puremagic.com/issues/show_bug.cgi?id=314 --- Comment #19 from Christian Kamm <kamm-removethis incasoftware.de> 2010-08-11 22:09:51 PDT --- Don, which version of the patch did you apply - the one attached here or the one I applied to LDC? Selective imports work correctly in LDC, so maybe there's some extra work needed for D2. I also expect the patch to require some work with regard to overload resolution, it works differently in D2. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 11 2010
http://d.puremagic.com/issues/show_bug.cgi?id=314 --- Comment #20 from Don <clugdbug yahoo.com.au> 2010-08-12 01:04:26 PDT --- (In reply to comment #19)Don, which version of the patch did you apply - the one attached here or the one I applied to LDC? Selective imports work correctly in LDC, so maybe there's some extra work needed for D2. I also expect the patch to require some work with regard to overload resolution, it works differently in D2.
The one attached here. Although I've found some problems with selective imports, I no longer think they are the fault of this patch. For example, the existing release of D1 doesn't like this example: --- import std.stdio : writefln; void main() { std.stdio.writefln("xyz"); } test0.d(338): Error: undefined identifier std Error: no property 'writefln' for type 'TOK149' test0.d(338): Error: function expected before (), not __error of type TOK149 --- After applying the patch and my change to Id::object, and fixing a bug in each of druntime, Phobos, and the test suite, all Phobos unittests pass, and the DMD test suite passes all tests. Looks great to me. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 12 2010
http://d.puremagic.com/issues/show_bug.cgi?id=314 --- Comment #21 from nfxjfg gmail.com 2010-08-12 06:11:44 PDT --- In my understanding, "import std.stdio : writefln;" only imports the name "writefln", not "std" and "writefln". If the user wants "std", he has to write "static import std.stdio;". I would assume your example is invalid and is expected to fail. Why would the user do "import std.stdio : writefln;" if he doesn't use writefln directly? Is "std.stdio.writefln" the only name he's supposed to be able to use here? If yes, what the hell is the use of that? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 12 2010
http://d.puremagic.com/issues/show_bug.cgi?id=314 --- Comment #22 from Don <clugdbug yahoo.com.au> 2010-08-12 07:09:34 PDT --- (In reply to comment #21)In my understanding, "import std.stdio : writefln;" only imports the name "writefln", not "std" and "writefln". If the user wants "std", he has to write "static import std.stdio;". I would assume your example is invalid and is expected to fail. Why would the user do "import std.stdio : writefln;" if he doesn't use writefln directly? Is "std.stdio.writefln" the only name he's supposed to be able to use here? If yes, what the hell is the use of that?
It's invalid code. But you should never see TOKxxx in an error message. It indicates something is fouled up. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 12 2010
http://d.puremagic.com/issues/show_bug.cgi?id=314 --- Comment #23 from Leandro Lucarella <llucax gmail.com> 2010-08-12 07:25:12 PDT --- (In reply to comment #22)(In reply to comment #21)In my understanding, "import std.stdio : writefln;" only imports the name "writefln", not "std" and "writefln". If the user wants "std", he has to write "static import std.stdio;". I would assume your example is invalid and is expected to fail. Why would the user do "import std.stdio : writefln;" if he doesn't use writefln directly? Is "std.stdio.writefln" the only name he's supposed to be able to use here? If yes, what the hell is the use of that?
It's invalid code. But you should never see TOKxxx in an error message. It indicates something is fouled up.
One more for bug 4329 =) -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 12 2010
http://d.puremagic.com/issues/show_bug.cgi?id=314 --- Comment #24 from Christian Kamm <kamm-removethis incasoftware.de> 2010-08-12 10:33:50 PDT --- (In reply to comment #20)(In reply to comment #19)Don, which version of the patch did you apply - the one attached here or the one I applied to LDC?
The one attached here.
Well, ass Walter pointed out the attached patch has problems with overload resolution. The corrected patch doesn't though. If you're interested in looking at it, I could make it work against the D2 frontend and post it here. I don't want the effort to be in vain though, so could you check with Walter whether he'd accept a patch that works as described in comment #9? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 12 2010
http://d.puremagic.com/issues/show_bug.cgi?id=314 --- Comment #25 from Christian Kamm <kamm-removethis incasoftware.de> 2010-08-12 10:45:00 PDT --- Gah, can you edit comments somehow? That typo is extremely embarrassing. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 12 2010
http://d.puremagic.com/issues/show_bug.cgi?id=314 Don <clugdbug yahoo.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #364 is|0 |1 obsolete| | --- Comment #26 from Don <clugdbug yahoo.com.au> 2010-08-12 12:08:52 PDT --- (From update of attachment 364) Marking this patch as obsolete, since it is not correct. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 12 2010
http://d.puremagic.com/issues/show_bug.cgi?id=314 --- Comment #27 from Don <clugdbug yahoo.com.au> 2010-08-19 07:39:48 PDT --- (In reply to comment #24)(In reply to comment #20)(In reply to comment #19)Don, which version of the patch did you apply - the one attached here or the one I applied to LDC?
The one attached here.
Well, as Walter pointed out the attached patch has problems with overload resolution. The corrected patch doesn't though. If you're interested in looking at it, I could make it work against the D2 frontend and post it here. I don't want the effort to be in vain though, so could you check with Walter whether he'd accept a patch that works as described in comment #9?
From discussion with Walter -- It's too difficult to evaluate the patch in its present form. It's in two parts, both diffed against the LDC codebase rather than DMD, and the context is really unclear -- it's not clear which functions are being patched. I don't think a complete patch is required for evaluation -- in fact, a complete patch would be more difficult to quickly understand. But if you can write the essence of the code here, which I think is really only a couple of functions, that should be enough. And with a explanation of what it's doing. Leave out the myriad of changes which are just passing the module handle around. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 19 2010
http://d.puremagic.com/issues/show_bug.cgi?id=314 --- Comment #28 from Christian Kamm <kamm-removethis incasoftware.de> 2010-08-20 07:48:05 PDT ---But if you can write the essence of the code here, which I think is really only a couple of functions, that should be enough.
AliasDeclaration and FuncAliasDeclaration get a new 'importprot' member which is set for aliases generated by the import declaration and stores the import's protection. In ScopeDSymbol::search, we discard aliases which shouldn't be accessible - unless it's a FuncAliasDeclaration, to avoid making a chain invisible because the first member is privately imported: + // hide the aliases generated by selective or renamed private imports + if (s && flags & 1) + if (AliasDeclaration* ad = s->isAliasDeclaration()) + // may be a private alias to a function that is overloaded. these + // are sorted out during overload resolution, accept them here + if (ad->importprot == PROTprivate && !ad->aliassym->isFuncAliasDeclaration()) + s = NULL; And for overload resolution, skip over functions that should be invisible: -int overloadApply(FuncDeclaration *fstart, +int overloadApply(Module* from, FuncDeclaration *fstart, int (*fp)(void *, FuncDeclaration *), void *param) ... if (fa) { - if (overloadApply(fa->funcalias, fp, param)) - return 1; + if (fa->getModule() == from || fa->importprot != PROTprivate) + if (overloadApply(from, fa->funcalias, fp, param)) + return 1; next = fa->overnext; -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 20 2010
http://d.puremagic.com/issues/show_bug.cgi?id=314 strtr despam.it changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |strtr despam.it --- Comment #29 from strtr despam.it 2010-10-28 22:26:20 PDT --- Frelling bug got me again :( Any progress? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 28 2010
http://d.puremagic.com/issues/show_bug.cgi?id=314 --- Comment #30 from strtr despam.it 2010-11-03 18:36:23 PDT --- How embarrassing this might be, this needs a warning on the website. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 03 2010
http://d.puremagic.com/issues/show_bug.cgi?id=314 --- Comment #30 from strtr despam.it 2010-11-03 18:36:23 PDT --- How embarrassing this might be, this needs a warning on the website. --- Comment #31 from strtr despam.it 2010-11-03 18:39:07 PDT --- How embarrassing this might be, this needs a warning on the website. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 03 2010
http://d.puremagic.com/issues/show_bug.cgi?id=314 Mike Parker <aldacron gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |aldacron gmail.com --- Comment #32 from Mike Parker <aldacron gmail.com> 2011-05-29 00:10:41 PDT --- I was just bitten by this one testing out a library I'm developing. I use private selective imports in it quite heavily. It was confused when I started getting conflicts. It only took a minute or two to figure out what was going on, but now I have to go through and eliminate all of the selective imports. This bug renders them useless. I'm amazed this has been open for so long. It seems like a pretty major issue to me. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 29 2011









d-bugmail puremagic.com 