www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10356] New: invalid reference to "this" in struct

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10356

           Summary: invalid reference to "this" in struct
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: druntime
        AssignedTo: nobody puremagic.com
        ReportedBy: szabobogdan yahoo.com


--- Comment #0 from Szabo Bogdan <szabobogdan yahoo.com> 2013-06-14 04:36:57
PDT ---
struct Test {
    string[] keys;

    Test opAssign(Test rhs){
        assert(this.keys !is null);
        assert(rhs.keys is null);

        keys ~= rhs.keys;

        return this;
    }
}

void main() {
    Test[string] data;
    Test t;

    data["test"] = t;
}


The output:

  core.exception.OutOfMemoryError

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 14 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10356


John Colvin <john.loughran.colvin gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |john.loughran.colvin gmail.
                   |                            |com


--- Comment #1 from John Colvin <john.loughran.colvin gmail.com> 2013-06-17
23:49:40 BST ---
Can't duplicate.

I'm not sure what those asserts are for, but the first one fails for the
obvious reason that the associative array hasn't been initialised. 

Without the asserts the code runs fine.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 17 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10356



--- Comment #2 from Szabo Bogdan <szabobogdan yahoo.com> 2013-06-17 22:04:05
PDT ---
(In reply to comment #1)
 Can't duplicate.
 
 I'm not sure what those asserts are for, but the first one fails for the
 obvious reason that the associative array hasn't been initialised. 
 
 Without the asserts the code runs fine.
I'm sorry... maybe the original program was striped too much... here is a program where i found the bug: import std.stdio; struct Test { string val = ""; string[] key; Test opAssign(Test val){ this.val = val.val; key ~= val.key; return this; } void append(Test t) { val ~= t.val; key ~= t.key; }; } void main() { Test t; t.val = "test"; Test[string] data; Test v; v.val = "asd"; data["test"] = v; writeln(v); writeln(data["test"]); data["test"].append(t); writeln(data["test"].key); writeln("done"); } Thanks! -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 17 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10356



--- Comment #3 from John Colvin <john.loughran.colvin gmail.com> 2013-06-18
15:18:54 BST ---
OK.

A minimized test case:

struct Test 
{
    byte val; //can be anything
    string[] key;

    Test opAssign(Test rhs) //if void, no error.
    {
        //any attempt to read key here causes a segfault or OutOfMemoryError.
        key ~= rhs.key;
        return this;
    }
}

void main()
{
    //only fails using associative array, normal assignment is fine.
    Test[string] data;

    data["test"] = Test();
}


In the meantime, use the signature "void opAssign(Test rhs)" and you'll
(probably) be ok.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 18 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10356


John Colvin <john.loughran.colvin gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|druntime                    |DMD
            Summary|invalid reference to "this" |AA of structs: opAssign
                   |in struct                   |error.
           Severity|normal                      |major


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 18 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10356


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE


--- Comment #4 from Kenji Hara <k.hara.pg gmail.com> 2013-09-07 10:07:18 PDT ---
*** This issue has been marked as a duplicate of issue 6178 ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 07 2013