Bug 23655 – __traits(toType) shatters modularity

Status
NEW
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-01-26T21:02:41Z
Last change time
2024-12-13T19:26:57Z
Assigned to
No Owner
Creator
Adam D. Ruppe
Moved to GitHub: dmd#20220 →

Comments

Comment #0 by destructionator — 2023-01-26T21:02:41Z
This might not technically be a bug since the spec says "a type that has been seen by the implementation" but this is is a bad feature regardless. ``` struct S {}; alias t = __traits(toType, "S6totype1S"); ``` then make a totype.d with `struct S {}` compile: $ dmd totype2.d totype2.d(3): Error: cannot determine `__traits(toType, "S6totype1S")` then compile: $ dmd totype.d totype2.d fine! then compile: $ dmd totype2.d totype.d totype2.d(3): Error: cannot determine `__traits(toType, "S6totype1S")` D has very few features that cross modules like this and they're bad to have. We should start removing these things, especially when they are unused and unnecessary, to remove potential for more serious order of eval bugs arising from them.
Comment #1 by maxsamukha — 2023-01-27T07:16:24Z
(In reply to Adam D. Ruppe from comment #0) > > D has very few features that cross modules like this and they're bad to > have. We should start removing these things, especially when they are unused > and unnecessary, to remove potential for more serious order of eval bugs > arising from them. If the trait was properly designed, modularity would be trivially achieved by an implicit local import - "Error: cannot determine" is a lie because the mangled name contains the module information. "toType" is a misnomer, though, as the trait should "just work" for any symbol.
Comment #2 by destructionator — 2023-01-27T13:17:01Z
It should really just be removed from the language, as it serves no purpose and opens up a massive can of worms.
Comment #3 by robert.schadek — 2024-12-13T19:26:57Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20220 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB