www.digitalmars.com         C & C++   DMDScript  

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


          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;

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

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`.

Mar 12 2021