www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6906] New: Cannot assign value into associative array if contains opAssign

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

           Summary: Cannot assign value into associative array if contains
                    opAssign
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: Jesse.K.Phillips+D gmail.com


--- Comment #0 from Jesse Phillips <Jesse.K.Phillips+D gmail.com> 2011-11-07
12:24:00 PST ---
This code fails to compile because the struct S implement opAssign and the
compiler tries using it rather than the associative arrays insert.

    void main() {
       S[string] ss;
       S s;

       ss["hello"] = s;
    }

    struct S {
       void opAssign(int i) {
       }
    }

test.d(6): Error: function test.S.opAssign (int i) is not callable using
argument types (S)
test.d(6): Error: cannot implicitly convert expression (s) of type S to int
test.d(6): Error: function test.S.opAssign (int i) is not callable using
argument types (S)
test.d(6): Error: cannot implicitly convert expression (s) of type S to int
PS C:\Documents and Settings\jphillips\src\Juno> dmd test.d
test.d(5): Error: function test.S.opAssign (int i) is not callable using
argument types (S)
test.d(5): Error: cannot implicitly convert expression (s) of type S to int
test.d(5): Error: function test.S.opAssign (int i) is not callable using
argument types (S)
test.d(5): Error: cannot implicitly convert expression (s) of type S to int

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 07 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6906


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au


--- Comment #1 from Don <clugdbug yahoo.com.au> 2011-11-07 23:07:16 PST ---
I don't think this is a bug. I think the behaviour is intuitive.
ss["hello"] = s; looks like an assignment, and it currently behaves like one.
This code doesn't compile, either:

       S[2] ss;
       S s;
       ss[0] = s;

As you've defined it, S cannot participate in any assignment of any kind. You
can't even write:
S s;
S t;
t = s;

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 07 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6906


Jesse Phillips <Jesse.K.Phillips+D gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |Jesse.K.Phillips+D gmail.co
                   |                            |m


--- Comment #2 from Jesse Phillips <Jesse.K.Phillips+D gmail.com> 2011-11-08
07:16:04 PST ---
Can I then say you aren't able to define opAssign for a struct and have it work
for associative arrays:

    void main() {
       S[string] ss;
       S s;

       ss["hello"] = s;
    }

    struct S {
       void opAssign(int i) {
       }
       void opAssign(S s) {
           this = s;
       }
    }

/tmp$ ./test
Segmentation fault

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 08 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6906


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code


--- Comment #3 from Don <clugdbug yahoo.com.au> 2011-11-08 22:59:29 PST ---
(In reply to comment #2)
 Can I then say you aren't able to define opAssign for a struct and have it work
 for associative arrays:
 
 /tmp$ ./test
 Segmentation fault

That's definitely a problem, but I don't think it has anything to do with AAs. This also creates a stack overflow: void main() { S s; S t; t = s; } struct S { void opAssign(S s) { this = s; } } Obviously it's changing 'this = XXX' into 'this.opAssign(XXX)'. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 08 2011