D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4527 - writeln/typeid to not expand aliases (for string types)
Summary: writeln/typeid to not expand aliases (for string types)
Status: RESOLVED WONTFIX
Alias: None
Product: D
Classification: Unclassified
Component: druntime (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: No Owner
URL:
Keywords: bootcamp
Depends on:
Blocks:
 
Reported: 2010-07-28 14:58 UTC by bearophile_hugs
Modified: 2020-01-16 13:40 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2010-07-28 14:58:21 UTC
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 Andrej Mitrovic 2013-09-26 07:18:41 UTC
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 Mathias LANG 2020-01-16 13:40:25 UTC
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.