Thread overview
[Issue 3491] New: typeof( (string[string]).init)) == AssociativeArray!(string, string), doesn't implicitly convert to string[string].
Nov 09, 2009
David Simcha
Dec 29, 2009
Rainer Schuetze
Jan 28, 2010
Don
Mar 09, 2010
Walter Bright
November 09, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3491

           Summary: typeof( (string[string]).init)) ==
                    AssociativeArray!(string, string), doesn't implicitly
                    convert to string[string].
           Product: D
           Version: 2.036
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: dsimcha@yahoo.com


--- Comment #0 from David Simcha <dsimcha@yahoo.com> 2009-11-09 08:29:51 PST ---
string[string][string] foo() {
    string[string][string] ret;
    ret["foo"] = (string[string]).init;
    return ret;
}

void main() {
    foo();
}


Error: cannot implicitly convert expression
(_D6object30__T16AssociativeArrayTAyaTAyaZ16AssociativeArray6__initZ) of type
AssociativeArray!(string,string) to string[string]

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 29, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3491


Rainer Schuetze <r.sagitario@gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch, rejects-valid
                 CC|                            |r.sagitario@gmx.de
           Severity|normal                      |regression


--- Comment #1 from Rainer Schuetze <r.sagitario@gmx.de> 2009-12-29 03:47:45 PST ---
A much simpler version also fails:

void main()
{
    int[int] s;
    s = s.init;
}

c:\l\dmd-2.036\windows\bin\..\..\src\druntime\import\object.di(294): Error:
cann
ot implicitly convert expression
(_D6object26__T16AssociativeArrayTiTiZ16Associa
tiveArray6__initZ) of type AssociativeArray!(int,int) to int[int]

This used to work for DMD 2.035, so it is a regression.

There seems to be some inconsistency whether to use the new implementation of associative arrays or the original type.

The following patch ensures usage of the library type for implicitely casting.

Index: mtype.c ===================================================================
--- mtype.c    (revision 317)
+++ mtype.c    (working copy)
@@ -6761,6 +6761,9 @@
 {   MATCH m;

     //printf("TypeStruct::implicitConvTo(%s => %s)\n", toChars(),
to->toChars());
+    if(to->ty == Taarray)
+    to = ((TypeAArray*)to)->getImpl()->type;
+
     if (ty == to->ty && sym == ((TypeStruct *)to)->sym)
     {    m = MATCHexact;        // exact match
     if (mod != to->mod)

Index: e2ir.c ===================================================================
--- e2ir.c    (revision 317)
+++ e2ir.c    (working copy)
@@ -3508,6 +3508,12 @@
     elem *e = e1->toElem(irs);
     Type *tfrom = e1->type->toBasetype();
     Type *t = to->toBasetype();        // skip over typedef's
+
+    if(tfrom->ty == Taarray)
+    tfrom = ((TypeAArray*)tfrom)->getImpl()->type;
+    if(t->ty == Taarray)
+    t = ((TypeAArray*)t)->getImpl()->type;
+
     if (t->equals(tfrom))
     goto Lret;

This causes some strange cast (pointer to AA - is this supposed to work?) in object.d to fail, but I could not find the place where this magic happens. So I changed the definition :

Index: object.di ===================================================================
--- object.di    (revision 222)
+++ object.di    (working copy)
@@ -300,5 +300,7 @@

     Value[Key] rehash() @property
     {
-        return cast(Value[Key]) _aaRehash(&p, typeid(Value[Key]));
+    Value[Key] aa;
+    aa.p = _aaRehash(&p, typeid(Value[Key]));
+        return aa;
     }

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


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrei@metalanguage.com


--- Comment #2 from Don <clugdbug@yahoo.com.au> 2010-01-28 11:10:22 PST ---
*** Issue 3709 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: -------
March 09, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3491


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |FIXED


--- Comment #3 from Walter Bright <bugzilla@digitalmars.com> 2010-03-08 22:25:41 PST ---
Fixed dmd 2.041

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