https://d.puremagic.com/issues/show_bug.cgi?id=8557
--- Comment #10 from yebblies <[email protected]> 2013-11-25 19:24:11 EST --- (In reply to comment #9) > (In reply to comment #8) > > Ok I added those cases too. > > Thank you, such small things improve the usability of D a lot. It's actually turned out worse than I thought. I think we should change the rules a little. These test cases should all compile, and the ones that don't currently work are commented out. - If the type is given try and match it - Else if each element has a key, default is AA otherwise is array - Vectors and pointers are treated the same as dynamic arrays - For static array inits with keys, the length is given by the static array - For dynamic array inits with keys, the length is given by the largest key void main() { { // normal array literal int[] a = [1, 2, 3]; int[3] b = [1, 2, 3]; static assert(!is(typeof({ int[int] c = [1, 2, 3]; }))); // need key for each element auto d = [1, 2, 3]; static assert(is(typeof(d) == int[])); // default is dynamic array } { // some keys, no gaps int[] a = [1 : 2, 3, 0 : 1]; int[3] b = [1 : 2, 3, 0 : 1]; static assert(!is(typeof({ int[int] c = [1 : 2, 3, 0 : 1]; }))); // need key for each element // auto d = [1 : 2, 3, 0 : 1]; // static assert(is(typeof(d) == int[])); // default to array when not enough keys } { // all keys, no gaps int[] a = [1 : 2, 2 : 3, 0 : 1]; int[3] b = [1 : 2, 2 : 3, 0 : 1]; int[int] c = [1 : 2, 2 : 3, 0 : 1]; auto d = [1 : 2, 2 : 3, 0 : 1]; static assert(is(typeof(d) == int[int])); // default to AA when has all keys } { // some keys, gap int[] a = [1 : 2, 3]; int[3] b = [1 : 2, 3]; // auto c = [1 : 2, 3]; // static assert(is(typeof(c) == int[])); // should fill in gaps with int.init } { // value is AA // int[int][int] a = [0 : [0 : 3]]; int[][int] b = [0 : [0 : 3]]; int[1][int] c = [0 : [0 : 3]]; // int[int][] d = [0 : [0 : 3]]; // int[int][1] e = [0 : [0 : 3]]; auto f = [0 : [0 : 3]]; // static assert(is(typeof(f) == int[int][int])); // default to AA when has all keys } { // key is AA int[int[int]] a = [[0 : 0] : 0]; // int[int[]] b = [[0 : 0] : 0]; // int[int[1]] c = [[0 : 0] : 0]; auto d = [[0 : 0] : 0]; static assert(is(typeof(d) == int[int[int]])); } { // value is array int[][int] a = [0 : [2, 3]]; int[][] b = [0 : [2, 3]]; int[2][int] c = [0 : [2, 3]]; int[2][] d = [0 : [2, 3]]; auto e = [0 : [2, 3]]; static assert(is(typeof(e) == int[][int])); } { // key is array int[int[]] a = [[2, 3] : 0]; int[int[2]] b = [[2, 3] : 0]; auto c = [[2, 3] : 0]; static assert(is(typeof(c) == int[int[]])); } { // value has gap // int[][int] a = [0 : [1 : 2, 3]]; int[][] b = [0 : [1 : 2, 3]]; // int[3][int] c = [0 : [1 : 2, 3]]; int[3][] d = [0 : [1 : 2, 3]]; // auto e = [0 : [1 : 2, 3]]; // static assert(is(typeof(e) == int[][int])); } { // key has gap // int[int[]] a = [[1 : 2, 3] : 0]; // int[int[3]] b = [[1 : 2, 3] : 0]; // auto c = [[1 : 2, 3] : 0]; // static assert(is(typeof(c) == int[int[]])); } } -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
