www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12604] New: No "mismatched array lengths" error with

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

          Issue ID: 12604
           Summary: No "mismatched array lengths" error with narrowing
                    conversions
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: accepts-invalid
          Severity: normal
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: k.hara.pg gmail.com

With the code, the initialization of 'a' and assignment of 'b' will cause two
compile time errors.

void main()
{
    int[1] a = [1,2,3];
    int[1] b; b = [1,2,3];
}
----
test.d(3): Error: mismatched array lengths, 1 and 3
test.d(4): Error: mismatched array lengths, 1 and 3

But if you replace 'int' with 'short', the compile-time errors will disappear.

void main()
{
    short[1] a = [1,2,3];
    short[1] b; b = [1,2,3];
}

Instead runtime exception is thrown.

object.Error (0): Array lengths don't match for copy: 3 != 1

--
Apr 20 2014