[Issue 21705] New: Nullable!T.opEquals fails for T with non-const opEquals overload

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Mar 12 23:07:30 UTC 2021


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

          Issue ID: 21705
           Summary: Nullable!T.opEquals fails for T with non-const
                    opEquals overload
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: snarwin+bugzilla at gmail.com

Example program:

---
import std.typecons;

struct S
{
    int n;
    bool opEquals(S rhs) { return n == rhs.n; }
}

void main()
{
    Nullable!S example = S();
    S s;
    assert(example.opEquals(s));
}
---

As of DMD 2.095.1, this program fails to compile, with the following error
message:

---
bug.d(13): Error: template `std.typecons.Nullable!(S).Nullable.opEquals` cannot
deduce function from argument types `!()(S)`, candidates are:
/usr/include/dmd/phobos/std/typecons.d(2720):        `opEquals()(auto ref
const(typeof(this)) rhs)`
/usr/include/dmd/phobos/std/typecons.d(2730):        `opEquals(U)(auto ref
const(U) rhs)`
  with `U = S`
  must satisfy the following constraint:
`       is(typeof(this.get == rhs))`
---


Note that an explicit call to opEquals is necessary to prevent the compiler
from falling back to the deprecated `alias get this`.

--


More information about the Digitalmars-d-bugs mailing list