www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5155] New: AssociativeArray.get does not compile when opBinary("in") is defined.

http://d.puremagic.com/issues/show_bug.cgi?id=5155

           Summary: AssociativeArray.get does not compile when
                    opBinary("in") is defined.
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: patch
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: sandford jhu.edu


--- Comment #0 from Rob Jacques <sandford jhu.edu> 2010-11-02 00:23:05 PDT ---
If an appropriate "in" opBinary function is defined, AA.get calls that instead
of the actual built-in "in" operator. As I can see no reason, type wise, for
this to be so, this may be rooted in a DMD error. Also, complex templates can
cause an ICE: I found this bug after tracing down an instance of Issue 5079
(glue.c, 1103) due to a std.variant unit test instantiating This[This]. 

Using DMD 2.050:
In Object.di:
Line 366:
-    void*  _aaIn(void* p, TypeInfo keyti);
+    void*  _aaIn(void* p, TypeInfo keyti,...);


Lines 413:
-        auto p = key in *cast(Value[Key]*)(&p);
+        auto ptr = cast(Value*) _aaIn(p,typeid(Key),key);

In Object_.d:
Line 2218:
-    void* _aaIn(void* p, TypeInfo keyti);
+    void* _aaIn(void* p, TypeInfo keyti,...);

Line 2296:
-    auto p = key in *cast(Value[Key]*)(&p);
+    auto ptr = cast(Value*) _aaIn(p,typeid(Key),key);

Test case (doesn't ICE):

struct Bug {
    int x;
    Bug opBinary(string op, T)(T rhs) { return Bug; }
}

void main(string[] args) {
    Bug key1   = Bug(1);
    Bug key2   = Bug(2);
    Bug value1 = Bug(3);
    Bug value2 = Bug(4);
    Bug[Bug] bug = [key1:value1];
    assert( bug.get(key1,value2).x == value1.x);
    assert( bug.get(key2,value2).x == value2.x);

    int[string] vals;
    vals["x"] = 1;
    assert( vals.get("x", 0) == 1 );
    assert( vals.get("y", 0) == 0 );

}

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