www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14759] New: Inconsistent behaviour of array element-wise


          Issue ID: 14759
           Summary: Inconsistent behaviour of array element-wise
           Product: D
           Version: D2
          Hardware: x86_64
               URL: http://forum.dlang.org/thread/ymundssikvjdvshpsqlj for
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: druntime
          Assignee: nobody puremagic.com
          Reporter: schuetzm gmx.net

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/ymundssikvjdvshpsqlj forum.dlang.org

Jul 02 2015