Bug 15359 – DMD incorrectly identifies type of multidimensional array

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Mac OS X
Creation time
2015-11-18T21:02:38Z
Last change time
2024-12-13T18:45:55Z
Keywords
diagnostic
Assigned to
No Owner
Creator
Jack Stouffer
Moved to GitHub: dmd#19072 →

Comments

Comment #0 by jack — 2015-11-18T21:02:38Z
----- void main() { int[5][2] data = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]]; } ------ prints ------ Error: cannot implicitly convert expression ([[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]]) of type int[][] to int[] ------
Comment #1 by tanel58 — 2015-11-18T21:06:43Z
I believe you mean "int[2][5] data = ...".
Comment #2 by jack — 2015-11-18T21:22:05Z
(In reply to Tanel Tagaväli from comment #1) > I believe you mean "int[2][5] data = ...". Yes I did. I improperly reduced a bug I ran into. Here is a better illustration of the problem ------ void main() { int[][] data = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]]; int[2][5] d = data; } ------ Maybe it's just a question of a bad error message, because if taking the data from a dynamic array and saving it into a static array is not allowed it should say something like ------ Error: cannot implicitly convert expression (data) of type int[][] to int[2][5] ------ But instead it says ------ Error: cannot implicitly convert expression (data) of type int[][] to int[] ------
Comment #3 by initrd.gz — 2015-11-18T22:07:59Z
(In reply to Jack Stouffer from comment #2) > (In reply to Tanel Tagaväli from comment #1) > > I believe you mean "int[2][5] data = ...". > > Yes I did. I improperly reduced a bug I ran into. > > Here is a better illustration of the problem > > ------ > void main() { > int[][] data = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]]; > int[2][5] d = data; > } > ------ > > Maybe it's just a question of a bad error message, because if taking the > data from a dynamic array and saving it into a static array is not allowed > it should say something like > > ------ > Error: cannot implicitly convert expression (data) of type int[][] to > int[2][5] > ------ > > But instead it says > > ------ > Error: cannot implicitly convert expression (data) of type int[][] to int[] > ------ Fixed-sized arrays (like `int[2][5]`) have different semantics than slices (like `int[][]`); you'll have to assign the elements manually.
Comment #4 by jack — 2015-11-18T23:56:26Z
(In reply to Alex Parrill from comment #3) > Fixed-sized arrays (like `int[2][5]`) have different semantics than slices > (like `int[][]`); you'll have to assign the elements manually. Ok, so it's a poor error message that should be fixed.
Comment #5 by robert.schadek — 2024-12-13T18:45:55Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19072 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB