www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6812] New: Failed equality of structs with string field

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

           Summary: Failed equality of structs with string field
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



This program produces a runtime assert error, it's a bug:


struct Foo {
    string s;
}
void main() {
    Foo b1 = Foo("hello".idup);
    Foo b2 = Foo("hello".idup);
    assert(b1 !is b2); // OK
    assert(b1 == b2);  // line 8, error
}


With DMD 2.056head it gives:

core.exception.AssertError test(8): Assertion failure


The equality among structs has to call the string equality of their fields. The
"is" operator has to compare the structs bitwise.

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




Class type has same problem.

struct Foo {
    string s;
}
struct Bar {
    static class X {
        bool opEquals(Object o){ return true; }
    }
    X x;
}
void main() {
    Foo f1 = Foo("hello".idup);
    Foo f2 = Foo("hello".idup);
    assert(f1 !is f2); // OK
    assert(f1 == f2);  // error

    Bar b1 = Bar(new Bar.X());
    Bar b2 = Bar(new Bar.X());
    assert(b1 !is b2);  // OK
    assert(b1 == b2);   // error!
}

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


Don <clugdbug yahoo.com.au> changed:

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



Looks like a dup of bug 3789

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


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE



*** This issue has been marked as a duplicate of issue 3789 ***

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