March 12, 2021 [Issue 21705] New: Nullable!T.opEquals fails for T with non-const opEquals overload | ||||
|---|---|---|---|---|
| ||||
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@puremagic.com Reporter: snarwin+bugzilla@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`. -- | ||||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply