On Friday, 5 August 2022 at 01:53:42 UTC, Ruby The Roobster wrote:
On Friday, 5 August 2022 at 01:38:48 UTC, jfondren wrote:

Here's a complete example that passes tests:

```d
struct S {
    int n;
    void opOpAssign(string op)(S rhs) if (op == "/") {
        n++;
    }
}

Nevermind.  I have to remove the trailing equals sign.

ah, so you had `(op == "/=")` instead?

I think this is a problem actually, maybe arguably not a bug, but not desirable. Consider:

```d
struct S {
    int n;
    void opOpAssign(string op)(S rhs) if (op == "/=") {
        n++;
    }
    void opOpAssign(string op)(S rhs) if (op == "/") {
        // do nothing
    }
}

unittest {
    auto a = S(1), b = S(2);
    a /= b;
    b /= a;
    assert(a.n == 2);
    assert(b.n == 3);
}
```

The test fails because the second definition is used (preventing a "none of the overlords are callable" error) and the first definition never matches because it's wrong. I say this arguably isn't a bug because it can still be used:

```d
    a.opOpAssign!"/="(b);
    b.opOpAssign!"/="(a);
```

but what's actually wanted is operator overloading and a mistake at the definition is silently allowed.
  • Unittest Absurdity Ruby The Roobster via Digitalmars-d-learn
    • Re: Unittest Absurdity Ruby The Roobster via Digitalmars-d-learn
      • Re: Unittest Absurdi... jfondren via Digitalmars-d-learn
        • Re: Unittest Abs... jfondren via Digitalmars-d-learn
          • Re: Unittest... Ruby The Roobster via Digitalmars-d-learn
            • Re: Uni... Ruby The Roobster via Digitalmars-d-learn
              • Re:... Ruby The Roobster via Digitalmars-d-learn
                • ... jfondren via Digitalmars-d-learn
            • Re: Uni... Paul Backus via Digitalmars-d-learn
              • Re:... Steven Schveighoffer via Digitalmars-d-learn
                • ... jfondren via Digitalmars-d-learn
                • ... Steven Schveighoffer via Digitalmars-d-learn
                • ... Steven Schveighoffer via Digitalmars-d-learn
                • ... frame via Digitalmars-d-learn
                • ... Steven Schveighoffer via Digitalmars-d-learn
                • ... frame via Digitalmars-d-learn

Reply via email to