I have tried to understand what's happening here, but I can't tell why some times it accepts the implicit string cast and other times it doesn't: import std.string: text; struct Foo1 { char[][] matrix; string spam() const pure { char[] m = text(matrix).dup; return m; // OK } } struct Foo2 { enum Bar : char { A } Bar[][] matrix; string spam1() const pure { return text(matrix).dup; // OK } string spam2() const pure { char[] m = text(matrix).dup; return m; // line 22, Error } char[][] matrix2; string spam3() const pure { char[] m = text(matrix2).dup; return m; // line 29, Error. } } void main() {} dmd 2.065.0b2 gives: test.d(22): Error: cannot implicitly convert expression (m) of type char[] to string test.d(29): Error: cannot implicitly convert expression (m) of type char[] to string If it's not a compiler bug then I think it's not easy for D newbies to learn such behaviours.
It's a bug, the compiler thinks that `const(Bar[])` could potentially produce a `char[]`. string func1(in char[] x) pure { char[] m = "".dup; return m; // works, can't get a char[] from const(char[]) without casting } enum Bar : char { A } string func2(in Bar[] x) pure { char[] m = "".dup; return m; // doesn't work, but should }
works since 2.072.2. (https://run.dlang.io/is/LeD6kN)