On 7/10/20 4:15 AM, Max Samukha wrote:
On Thursday, 9 July 2020 at 21:04:57 UTC, Steven Schveighoffer wrote:
Why isn't [] accepted as an empty AA literal?
Because it's an empty dynamic array literal.
If D were to accept an empty AA literal, I'd expect it to be [:].
Just as typeof(null) is a subtype of all nullable types, you could make
typeof([]) a subtype of both AAs and dynamic arrays. [:] could still be
made a specifically AA literal.
Sure it's possible. But I don't see it happening.
BTW, writeln((int[int]).init) prints "[]" (to!string((V[K]).init) ==
"[]"), but pragma(msg, (int[int]).init) - the more general 'null'
((V[K]).init.stringof == "null"), which is a unfortunate inconsistency.
to!string is from the library, pragma(msg) is the compiler. The latter
is authoratative where the compiler is concerned.
to!string probably should be changed. [] should be printed for
initialized but empty AAs, null should be printed for .init.
-Steve