Bug 4527 – writeln/typeid to not expand aliases (for string types)

Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P2
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-07-28T14:58:21Z
Last change time
2020-01-16T13:40:25Z
Keywords
bootcamp
Assigned to
No Owner
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2010-07-28T14:58:21Z
This is a D2 program: import std.stdio: writeln; void main() { writeln(typeid(string)); writeln(typeid(wstring)); writeln(typeid(dstring)); } I'd like the output of that program to be: string wstring dstring Instead of (dmd 2.047): immutable(char)[] immutable(wchar)[] immutable(dchar)[] "immutable(dchar)[]" is less readable, and dstring is a standard built-in alias in D2. Making them readable is especially important when string types are inside more complex types, to decrease the visual noise a lot. Example: import std.stdio; void main() { wstring[string[dstring]] a; writeln(typeid(typeof(a))); } Prints an unreadable: immutable(wchar)[][const(immutable(char)[])[immutable(dchar)[]]] While this is almost readable still: wstring[string[dstring]] See also bug 3086
Comment #1 by andrej.mitrovich — 2013-09-26T07:18:41Z
I don't like special-casing, but I do agree the output would be more readable. Perhaps we need to introduce a new function that outputs a more readable string representation. Not sure..
Comment #2 by pro.mathias.lang — 2020-01-16T13:40:25Z
Closing as WONTFIX. Rationale: Aliases are defined as being "transparent". This is currently in the spec, and what the compiler does. However people (including me) have come to expect aliases to be retained while being transparent. We added a bit of special-casing in the compiler to show 'string' when the type is 'immutable(char)[]'. It didn't resolve the core issue, but it did mitigate the problem. However, typeid relies on the generated typeinfo. Having alias generate their own typeinfo would bloat the binary to an impossible extent. Bear in mind that aliases are used everywhere in the compiler, so distinguishing between user-provided and compiler-generated aliases is a huge undertaking. For example, the names of template parameter are aliases. Putting aside the extremely negative impact it'd have on binary size, typeid is not that used in modern D code, so I doubt the feature is more than a nice to have nowadays.