[Issue 14759] New: Inconsistent behaviour of array element-wise operations

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Jul 2 05:27:23 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=14759

          Issue ID: 14759
           Summary: Inconsistent behaviour of array element-wise
                    operations
           Product: D
           Version: D2
          Hardware: x86_64
               URL: http://forum.dlang.org/thread/ymundssikvjdvshpsqlj@for
                    um.dlang.org
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: druntime
          Assignee: nobody at puremagic.com
          Reporter: schuetzm at 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

--


More information about the Digitalmars-d-bugs mailing list