digitalmars.D.bugs - [Issue 12606] New: Mismatch of array length during assignment should
- via Digitalmars-d-bugs (39/39) Apr 21 2014 https://issues.dlang.org/show_bug.cgi?id=12606
https://issues.dlang.org/show_bug.cgi?id=12606 Issue ID: 12606 Summary: Mismatch of array length during assignment should emit better diagnostics Product: D Version: D2 Hardware: All OS: All Status: NEW Keywords: diagnostic Severity: enhancement Priority: P1 Component: DMD Assignee: nobody puremagic.com Reporter: andrej.mitrovich gmail.com ----- import std.range; // ok uint[256] arr1 = iota(0, 512).array[0 .. 256]; // diagnostic mentions int[] => uint[256], but no mention of length (128 != 256) uint[256] arr2 = iota(0, 512).array[0 .. 128]; void main() { } ----- The first one is a relatively recent feature, where a slice can be converted to a static array if the length is known. The length is also known for the second declaration, but it's not being taken into account by the diagnostic: Diagnostic: test.d(6): Error: cannot implicitly convert expression ([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127]) of type int[] to uint[256] Since the compiler knows the length of the slice it should mention the mismatch of slice lengths when attempting to convert a dynamic array to a static array. --
Apr 21 2014