Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent abilities to compare const/immutable classes #18716

Open
dlangBugzillaToGithub opened this issue Nov 23, 2013 · 0 comments
Open

Comments

@dlangBugzillaToGithub
Copy link

Denis Shelomovskii (@denis-sh) reported this on 2013-11-23T23:50:11Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=11588

Description

Currently because of Issue 1824 `opEquals` and `opCmp` aren't `const`.

dmd rejects `opCmp` calls but accepts `opEquals` ones:
---
class C
{
    int i;
    override bool opEquals(Object o) { ++i; return true;}
    override int opCmp(Object c) { ++i; return 0; }
}

void main()
{
    const c1 = new C, c2 = new C;
    assert(c1 == c2); // ok, calls `opEquals`
    assert(c1 <= c2); // Error: mutable method main.C.opCmp is not callable using a const object
}
---

Both should be either accepted or rejected. See Issue 11557 for proposal to allow `opCmp` calls too.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant