[Issue 12604] New: No "mismatched array lengths" error with narrowing conversions
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sun Apr 20 17:16:40 PDT 2014
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 at puremagic.com
Reporter: k.hara.pg at 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
--
More information about the Digitalmars-d-bugs
mailing list