import std.string; import std.stdio; struct Wrap { string _payload; alias _payload this; } void main() { Wrap foo; string x = format("%s %s", "1", "2"); foo ~= x; writeln(foo); // writes: 1 2 Wrap bar; bar ~= format("%s %s", "1", "2"); writeln(bar); // writes: (immutable(char)[],immutable(char)[],immutable(char)[])1 2 } What's going on here?
This is a regression of fixing bug 7583. Reduced test case: ---- struct S { int[] arr; alias arr this; } S func(...) { S ret; ret.arr.length = _arguments.length; return ret; } void main() { int[] arr; assert(arr.length == 0); arr ~= func(1, 2); //NG //arr = func(1, 2); //OK assert(arr.length == 2); } Pull request: https://github.com/D-Programming-Language/dmd/pull/885
See also 7598
(In reply to comment #2) > See also 7598 See also issue 7598
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/a235ba424a9095b5ca2cc08f6c3444354c1a0013 fix Issue 7922 - alias this causes weird formatting issues for strings This was a regression of fixing 7583, and redundant copy of syntax tree have been made this problem. So I revert efd4711 + cd7dfca, and add necessary and sufficient copy. https://github.com/D-Programming-Language/dmd/commit/3ecc1f3fbfd1d821bd647bde2e9d4adbcf9f2b9d Merge pull request #885 from 9rnsr/fix7922 Issue 7922 - alias this causes weird formatting issues for strings