www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22159] New: "==" causeses error for array of classes in safe

https://issues.dlang.org/show_bug.cgi?id=22159

          Issue ID: 22159
           Summary: "==" causeses error for array of classes in safe
                    method
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: lucidanescu28 yahoo.com

The following code compiles:

class C { int a; this(int)  safe {} }

void main()
{
    C c = new C(1);
    C[] a = [c, c, c];
    assert(a == [c, c, c]);
}

The following code fails:

class C { int a; this(int)  safe {} }

 safe void main()
{
    C c = new C(1);
    C[] a = [c, c, c];
    assert(a == [c, c, c]);
}

with the message: incompatible types for array comparison: `C[]` and `C[3]`

--
Jul 30 2021