digitalmars.D.bugs - [Issue 10562] New: Cannot initialize arrays by an element value when the elements are fixed-length arrays
- d-bugmail puremagic.com (43/43) Jul 06 2013 http://d.puremagic.com/issues/show_bug.cgi?id=10562
- d-bugmail puremagic.com (14/14) Jul 07 2013 http://d.puremagic.com/issues/show_bug.cgi?id=10562
http://d.puremagic.com/issues/show_bug.cgi?id=10562 Summary: Cannot initialize arrays by an element value when the elements are fixed-length arrays Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: acehreli yahoo.com We know that arrays can be initialized by a single element value: void main() { int value = 1; int[2] a = value; assert(a == [ 1, 1 ]); } The bug is that it does not work when the elements are fixed-length arrays themselves: void main() { int[3] value = [ 1, 2, 3 ]; int[3][2] a = value; // <-- COMPILATION ERROR assert(a == [ [ 1, 2, 3 ], [ 1, 2, 3 ] ]); } Error: mismatched array lengths, 6 and 3 On the other hand, the array can be initialized by an element-of-an-element: void main() { // Note: This is the type of an element of array elements int value = 1; int[3][2] a = value; assert(a == [ [ 1, 1, 1 ], [ 1, 1, 1 ] ]); } Is that a feature or perhaps a consequence of the reported bug? Ali -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 06 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10562 Maxim Fomin <maxim maxim-fomin.ru> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |maxim maxim-fomin.ru --- From the spec: "If a slice operator appears as the lvalue of an assignment expression, and the type of the rvalue is the same as the element type of the lvalue, then the lvalue's array contents are set to the rvalue. " Assuming that single value initialization is a semantic equivalent of slice expression, the code should work. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 07 2013