[Issue 21705] 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:23:31 UTC 2021


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

--- Comment #1 from Paul Backus <snarwin+bugzilla at gmail.com> ---
Another example:

---
import std.typecons;

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

void main()
{
    Nullable!S example1 = S(1), example2 = S(1);
    assert(example1 == example2);
}
---

Produces the following error message with DMD 2.095.1:

---
/usr/include/dmd/phobos/std/typecons.d(2726): Error: mutable method
`bug.S.opEquals` is not callable using a `const` object
bug.d(6):        Consider adding `const` or `inout` here
bug.d(12): Error: template instance
`std.typecons.Nullable!(S).Nullable.opEquals!()` error instantiating
---

--


More information about the Digitalmars-d-bugs mailing list