Bug 3491 – typeof( (string[string]).init)) == AssociativeArray!(string, string), doesn't implicitly convert to string[string].

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2009-11-09T08:29:00Z
Last change time
2015-06-09T01:27:05Z
Keywords
patch, rejects-valid
Assigned to
nobody
Creator
dsimcha

Comments

Comment #0 by dsimcha — 2009-11-09T08:29:51Z
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]
Comment #1 by r.sagitario — 2009-12-29T03:47:45Z
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; }
Comment #2 by clugdbug — 2010-01-28T11:10:22Z
*** Issue 3709 has been marked as a duplicate of this issue. ***
Comment #3 by bugzilla — 2010-03-08T22:25:41Z
Fixed dmd 2.041