Bug 14759 – Inconsistent behaviour of array element-wise operations

Status
NEW
Severity
normal
Priority
P3
Component
druntime
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2015-07-02T12:27:23Z
Last change time
2024-12-07T13:35:33Z
Assigned to
No Owner
Creator
Marc Schütz
Moved to GitHub: dmd#17306 →

Comments

Comment #0 by schuetzm — 2015-07-02T12:27:23Z
import std.stdio; void main() { int[] a = [1,1,1,1]; int[] b = [1,1,1,1]; int[] c; int[2] d; c[] = a[] - b[]; // works c.writeln; // [] d[] = a[] - b[]; // works d.writeln; // [0, 0] d[] = a[]; // throws! // object.Error@(0): Array lengths don't match for copy: 4 != 2 } In the case of subtraction, it assigns only as many elements as the destination has, but for direct assignment, it throws an error. This is clearly inconsistent. An error should be thrown in all cases, instead of silently dropping elements. Reported by ixid: http://forum.dlang.org/thread/[email protected]
Comment #1 by robert.schadek — 2024-12-07T13:35:33Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17306 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB