Bug 7922 – alias this causes weird formatting issues for strings

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-04-16T06:26:00Z
Last change time
2012-05-21T17:00:11Z
Keywords
pull, wrong-code
Assigned to
nobody
Creator
andrej.mitrovich

Comments

Comment #0 by andrej.mitrovich — 2012-04-16T06:26:12Z
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?
Comment #1 by k.hara.pg — 2012-04-16T23:49:12Z
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
Comment #2 by lovelydear — 2012-04-20T02:18:55Z
See also 7598
Comment #3 by lovelydear — 2012-04-20T02:19:55Z
(In reply to comment #2) > See also 7598 See also issue 7598
Comment #4 by github-bugzilla — 2012-05-21T14:59:47Z
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