Bug 24216 – All symbols from object are publicly imported into every module

Status
NEW
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-11-01T21:19:54Z
Last change time
2024-12-13T19:31:25Z
Keywords
accepts-invalid
Assigned to
No Owner
Creator
Steven Schveighoffer
Moved to GitHub: dmd#20347 →

Comments

Comment #0 by schveiguy — 2023-11-01T21:19:54Z
Has happened all the way back to at least 2.060 ```d import std.math; std.math.string s = "hello"; ``` Substitute `std.math` for any other module (including a completely empty module). Substitute `string` for any other symbol in object.d. As long as the module doesn't redefine that symbol, it's a pass-through for object symbols. Fully-qualified-names should only resolve to names defined within that module.
Comment #1 by destructionator — 2023-11-01T22:21:20Z
Not specific to object, this happens with all modules, but also not all symbols, it only applies to types. Does not happen with variables or functions.
Comment #2 by schveiguy — 2023-11-01T23:38:29Z
Please post examples to confirm. I tried this, and it compiles, so it's not just types: ```d import std.math; void main() { int[int] x; std.math.require(x, 5) = 6; } ```
Comment #3 by destructionator — 2023-11-01T23:59:51Z
OK, this gets weirder and weirder. Make three modules: mod.d ``` import mod2; import std.math; void main() { string[int] x; // mod2.Object lol = mod2.require(x, 5); mod2.bar test = mod2.lol; } ``` mod2.d ``` import mod3; void foo() {} ``` mod3.d ``` struct bar {} bar lol; ``` Error: undefined identifier `lol` in module `mod2`, did you mean variable `lol`? It allowed mod2.bar, the type, but not mod2.lol, the variable. This shows something is off without being just `object`. Swap the commented lines and again it allows mod2.Object but not mod2.require. Appears to be the same behavior with `object`. Now change the name to twoname.mod2 instead of mod2. No difference. But now use std.math instead and instead of "undefinied identifier require" you get "cannot implicitly convert expression require". So why is it different with a user-defined module than with std.math?
Comment #4 by schveiguy — 2023-11-02T00:12:20Z
FWIW, this was found in discord by someone asking what `std.stdio.string` is. So it's not just std.math. I just picked std.math as something I thought would likely not be dealing with `string`. But I also tried local modules without anything in it, and `mod1.string` worked.
Comment #5 by robert.schadek — 2024-12-13T19:31:25Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20347 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB