Jump to page: 1 2
Thread overview
[Issue 2451] New: Cannot add a Variant to associative array
Nov 13, 2008
d-bugmail
Feb 22, 2009
d-bugmail
Jan 15, 2010
David Simcha
[Issue 2451] Adding structs that use opAssign or postblit to an AA is broken
Feb 15, 2010
GG
May 22, 2010
Don
Jun 14, 2010
Don
Jun 14, 2010
Don
Jun 23, 2010
Don
Aug 19, 2010
Don
Oct 19, 2010
Don
Oct 19, 2010
Don
Oct 20, 2010
Walter Bright
November 13, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2451

           Summary: Cannot add a Variant to associative array
           Product: D
           Version: 2.020
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: critical
          Priority: P2
         Component: Phobos
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: samukha@voliacable.com


import std.variant;

void main()
{
    Variant[string] a;
    Variant v = 1;
    a["wut?"] = v;
}
----
core.exception.ArrayBoundsException@Test(23): Array index out of bounds

Key type is irrelevant.


-- 

February 22, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2451





------- Comment #1 from andrei@metalanguage.com  2009-02-22 09:39 -------
(In reply to comment #0)
> import std.variant;
> 
> void main()
> {
>     Variant[string] a;
>     Variant v = 1;
>     a["wut?"] = v;
> }
> ----
> core.exception.ArrayBoundsException@Test(23): Array index out of bounds
> 
> Key type is irrelevant.
> 

I reduced this further:

struct Wyda
{
    void opAssign(Wyda) {assert(&this !is null);}
}

void main()
{
    Wyda[int] a;
    a[4] = Wyda();
}

The assert will fail! Hash tables for value types that define opAssign seem to have a problem.


-- 

October 11, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2451


Andrei Alexandrescu <andrei@metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |andrei@metalanguage.com
         AssignedTo|nobody@puremagic.com        |andrei@metalanguage.com


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 15, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=2451


David Simcha <dsimcha@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dsimcha@yahoo.com


--- Comment #2 from David Simcha <dsimcha@yahoo.com> 2010-01-15 12:20:57 PST ---
Adding structs that use opAssign or postblit to an AA is broken.  The following also produces a range violation:

struct Foo {
    this(this){}
}

void main() {
    Foo[string] stuff;
    stuff["foo"] = Foo.init;
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 15, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=2451



--- Comment #3 from Andrei Alexandrescu <andrei@metalanguage.com> 2010-01-15 13:16:14 PST ---
Perfect timing, thanks. I just ran into that but had no time to investigate. The type Tuple!(uint, "count", float, "distance")[uint] does not work, but the type S[uint] (where struct S { uint count; float distance; }) does work.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 15, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=2451


GG <ggcoding@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ggcoding@gmail.com


--- Comment #4 from GG <ggcoding@gmail.com> 2010-02-15 12:14:09 PST ---
import std.variant;

Variant[char[]][int] aa;

aa[0]["a"] = "bla0";
aa[0]["b"] = 100;

aa[1]["a"] = "bla1";
aa[1]["b"] = 200;

With 32-bit Linux and dmd2.039 or dmd2.040
Compile : success
Running : core.exception.RangeError@test(30): Range violation

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 22, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=2451



--- Comment #5 from Don <clugdbug@yahoo.com.au> 2010-05-22 07:15:10 PDT ---
I don't have a patch for this, but the direct reason for the observed behaviour
is in expression.c, line 9023. If the type being inserted has an opAssign
overload, then it drops out of AssignExp::semantic() immediately and discards
the rest of the expression.
This isn't a real patch, since it still doesn't call postblit.

    /* If it is an assignment from a 'foreign' type,
     * check for operator overloading.
     */
    if (t1->ty == Tstruct)
    {
        StructDeclaration *sd = ((TypeStruct *)t1)->sym;
        if (op == TOKassign)
        {
            Expression *e = op_overload(sc);

+            if (e1->op==TOKindex &&
+                ((IndexExp *)e1)->e1->type->toBasetype()->ty == Taarray)
+            {
+            // If it is an AA, the assignment
+            // should be treated as a function call (Bugzilla 2451)
+            }
+            else
             if (e)
                return e;
        }

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 14, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=2451


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |cristian@zerobugs.org


--- Comment #6 from Don <clugdbug@yahoo.com.au> 2010-06-14 01:32:05 PDT ---
*** Issue 2938 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 14, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=2451


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs@eml.cc


--- Comment #7 from Don <clugdbug@yahoo.com.au> 2010-06-14 06:46:04 PDT ---
*** Issue 4121 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 23, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=2451


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |NEW


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
« First   ‹ Prev
1 2