Bug 12604 – No "mismatched array lengths" error with narrowing conversions
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-04-21T00:16:00Z
Last change time
2014-04-21T09:33:50Z
Keywords
accepts-invalid, pull
Assigned to
nobody
Creator
k.hara.pg
Comments
Comment #0 by k.hara.pg — 2014-04-21T00:16:40Z
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