www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12108] New: Array comparison throws 'TypeInfo.equals is not implemented'


           Summary: Array comparison throws 'TypeInfo.equals is not
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: druntime
        AssignedTo: nobody puremagic.com
        ReportedBy: stanislav.blinov gmail.com

--- Comment #0 from Stanislav Blinov <stanislav.blinov gmail.com> 2014-02-08
08:14:08 PST ---
When struct's member field's type has non-const opEquals defined, comparing
arrays of these structs throws an exception with not very helpful error

struct A {
    bool opEquals(A s) { return false; }

struct B {
    A a;

void main(){
    A a1, a2;
    if (a1 == a2) {}     //ok
    if ([a1] == [a2]) {} //ok
    B b1, b2;
    if (b1 == b2) {}     //ok
    if ([b1] == [b2]) {} // throws object.Error: TypeInfo.equals is not

Making opEquals const gets rid of the exception.

It's not clear why it happens at runtime as opposed to compile time, and the
message doesn't really explain what's going on.

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