Bug 9429 – Inconsistent runtime error of array.dup assignment for misaligned types.

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-01-30T18:10:00Z
Last change time
2013-11-07T11:17:09Z
Assigned to
nobody
Creator
estewh

Comments

Comment #0 by estewh — 2013-01-30T18:10:37Z
Given some bug infested code: struct hackit { float[3] mine; void opAssign(E)(in E val) if(isArray!E) { mine = cast(const float[]))(val.dup); } } void main() { hackit v; float[3] v1 = cast(const float[])([1.0, 2.0, 3.0]); // OK, no error v = [1.0, 2.0, 3.0]; // Fails at runtime with error message below } This error is thrown at runtime: "object.Error: lengths don't match for array copy, 3 = 6" It is correct, although misleading. Both arrays are length 3 and I believe this should be: object.Error: array cast misalignment Swapping the types in the above code gives the error: "object.Error array cast misalignement"
Comment #1 by estewh — 2013-01-30T18:37:18Z
Just some additional info: The error itself *is* correct, I'm only reporting that the message is misleading...if possible it would be nice to see it at compile time. I tested on the following configurations: OS: fedora 18 x86_64. Compiler: DMD 2.061 64 bit Binary produced: elf64-x86-64 OS: Windows 7 64 bit Compiler: DMD 2.061 32 bit Binary produced: 32 bit The messages are virtually the same on both systems.
Comment #2 by verylonglogin.reg — 2013-11-07T11:17:09Z
The testcase can be reduced to this: --- float[3] arr = [1.0, 2.0, 3.0].dup; --- Here array of 3 `double`s is created, duplicated, and converted to 6 `float`s which than correctly fails on copying to 3 `float`s. So the problem is the compiler allows such initialization. Opened Issue 11470 for this.