[Issue 2006] Appending empty array using ~= cast(T[]) [] doesn't work

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Feb 3 17:10:51 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=2006


Stewart Gordon <smjg at iname.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Empty array literals with   |Appending empty array using
                   |explicit type implicitly    |~= cast(T[]) [] doesn't
                   |convert to any array type   |work


--- Comment #8 from Stewart Gordon <smjg at iname.com> 2012-02-03 17:10:48 PST ---
The recent change to the summary line is wrong.

If they merely implicitly converted to any array type, the original code would
behave correctly, because the semantic analyser always attempts an exact match
before an implicit conversion match.  Clearly something else is going on.

(DMD 2.057 Win32)
----- bz2006.d -----
import std.stdio;

pragma(msg, typeof(cast(string[]) []));

void main() {
    string[][] aas = [];
    aas ~= cast(string[]) [];
    writefln("%d", aas.length);
    aas ~= (string[]).init;
    writefln("%d", aas.length);
    aas = aas ~ cast(string[]) [];
    writefln("%d", aas.length);

    auto empty = cast(string[]) [];
    pragma(msg, typeof(empty));
    aas ~= empty;
    writefln("%d", aas.length);
}
----------
C:\Users\Stewart\Documents\Programming\D\Tests\bugs>dmd bz2006.d
string[]
string[]

C:\Users\Stewart\Documents\Programming\D\Tests\bugs>bz2006
0
1
2
3
----------

Going by this, the problem seems to occur only with this specific
representation of an empty array, and only when it is applied directly to ~=
and not passed through a variable.

So it isn't an implicit conversion problem.  It would seem that DMD
special-cases this form, but this special-casing is broken.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list