Bug 21508 – private class p in file p.d visible outside the file (module)
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2020-12-27T12:55:09Z
Last change time
2021-02-06T12:48:37Z
Keywords
pull
Assigned to
No Owner
Creator
kdevel
Comments
Comment #0 by kdevel — 2020-12-27T12:55:09Z
According to Issue 1441 private classes should not be visible outside the module it is defined in. If the class is named after the basename of the module's file the protection does not work:
---p.d
module p;
private class p {}
---
---m.d
unittest {
import p;
import std.typecons;
// p.p is private, code should not compile
static assert (! __traits (compiles, (new p)));
}
---
$ dmd -unittest -main -run m
m.d(5): Error: static assert: !__traits(compiles, new p) is false
Issue mentioned in http://forum.dlang.org/thread/[email protected]
If the file p.d is renamed in say P.d and import p is changed to import P the unittest passes.
Comment #1 by dlang-bot — 2021-02-03T11:28:33Z
@Geod24 created dlang/dmd pull request #12178 "Fix 21508: Do not look inside imports that shadow a symbol" fixing this issue:
- Fix 21508: Do not look inside imports that shadow a symbol
There was a special case to look inside an import instead of showing
the conflict. This isn't consistent with the way imports appear to
the user (e.g. `class std {}` will conflict with `import std.stdio`),
so we just remove the special case and that solves the issue.
https://github.com/dlang/dmd/pull/12178
Comment #2 by dlang-bot — 2021-02-06T12:48:37Z
dlang/dmd pull request #12178 "Fix 21508: Do not look inside imports that shadow a symbol" was merged into master:
- 1d2bdbb597344b6398e6db7d9b4586dcf14735bc by Geod24:
Fix 21508: Do not look inside imports that shadow a symbol
There was a special case to look inside an import instead of showing
the conflict. This isn't consistent with the way imports appear to
the user (e.g. `class std {}` will conflict with `import std.stdio`),
so we just remove the special case and that solves the issue.
https://github.com/dlang/dmd/pull/12178