D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7922 - alias this causes weird formatting issues for strings
Summary: alias this causes weird formatting issues for strings
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 regression
Assignee: No Owner
URL:
Keywords: pull, wrong-code
Depends on:
Blocks:
 
Reported: 2012-04-16 06:26 UTC by Andrej Mitrovic
Modified: 2012-05-21 17:00 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrej Mitrovic 2012-04-16 06:26:12 UTC
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 Kenji Hara 2012-04-16 23:49:12 UTC
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 SomeDude 2012-04-20 02:18:55 UTC
See also 7598
Comment 3 SomeDude 2012-04-20 02:19:55 UTC
(In reply to comment #2)
> See also 7598

See also issue 7598
Comment 4 github-bugzilla 2012-05-21 14:59:47 UTC
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