D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2892 - Appending U[] to T[] where U : T but U != T yields corrupted results
Summary: Appending U[] to T[] where U : T but U != T yields corrupted results
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 major
Assignee: No Owner
URL:
Keywords: wrong-code
: 2910 2912 (view as issue list)
Depends on:
Blocks:
 
Reported: 2009-04-24 20:25 UTC by David Simcha
Modified: 2015-06-09 01:26 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description David Simcha 2009-04-24 20:25:19 UTC
import std.stdio;

void main() {
    uint[] foo = [1,2,3,4,5];
    ubyte[] bar = [1,2,3,4];
    foo ~= bar;
    writeln(foo);  // 1 2 3 4 5 67305985
    foo.length = 5;
    ulong[] baz = [1,2,3,4];
    foo ~= baz;
    writeln(foo);  // 1 2 3 4 5 1 0 2 0 3 0 4 0
}
Comment 1 Don 2009-04-29 10:31:42 UTC
*** Bug 2910 has been marked as a duplicate of this bug. ***
Comment 2 David Simcha 2009-04-29 15:19:13 UTC
*** Bug 2912 has been marked as a duplicate of this bug. ***
Comment 3 David Simcha 2009-04-29 15:26:05 UTC
Also, this doesn't happen only for array literals.  Here, I .dup the literals to make sure they're allocated like "normal" arrays and it still happens.

import std.stdio;

void main() {
    uint[] foo = [1U,2,3,4,5].dup;
    ubyte[] bar = [cast(ubyte) 1,2,3,4].dup;
    foo ~= bar;
    writeln(foo);  // 1 2 3 4 5 67305985
    foo.length = 5;
    ulong[] baz = [1UL,2,3,4].dup;
    foo ~= baz;
    writeln(foo);  // 1 2 3 4 5 1 0 2 0 3 0 4 0
}
Comment 4 Don 2009-04-29 23:32:31 UTC
Could this be a regression?
Comment 5 David Simcha 2009-12-05 18:27:04 UTC
Fixed a long time ago.