Bug 9381 – package access can be abused and worked around
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-01-23T18:05:00Z
Last change time
2016-08-27T23:01:22Z
Assigned to
nobody
Creator
andrej.mitrovich
Comments
Comment #0 by andrej.mitrovich — 2013-01-23T18:05:26Z
/a/m.d:
module a.m;
package void foo() { }
/user/a/workaround.d:
module a.workaround;
import a.m;
auto foo()
{
return a.m.foo(); // free access!
}
/user/main.d:
module main;
import a.workaround;
void main()
{
foo();
}
$ rdmd user/main.d
No compile errors!
Even though user/a/workaround is *not* part of the library defined in the 'a' folder, it has free access to all package 'a' modules.
Package should probably be checked on a folder level and not just on a module declaration level to make it useful.
Comment #1 by andrej.mitrovich — 2013-01-23T18:07:47Z
(In reply to comment #0)
> Package should probably be checked on a folder level and not just on a module
> declaration level to make it useful.
Although if a library writer has e.g. 'foo/bar' package split around multiple directories and is using import switches, then this would break his code.
So this could end up being a stale-mate, unless we re-design access modifiers altogether (a DIP was already called for by Walter).
Comment #2 by Oleg.Kuporosov — 2013-01-24T03:47:44Z
Comment #3 by andrej.mitrovich — 2013-01-24T06:39:03Z
(In reply to comment #2)
> Isn't a dup of http://d.puremagic.com/issues/show_bug.cgi?id=143 ?
No, that's related to package not working on variables. It works on functions, but as the sample shows it can be easily worked around.
Comment #4 by andrej.mitrovich — 2016-08-27T23:01:22Z
Nah, we can't really do this as it might be possible that some projects use multiple package roots and multiple import paths. It's really a non-issue.