Just thought I'd let you know that the following functions in Object are not const correct in D2:
void print();
string toString();
int opEquals(Object o);
int opCmp(Object o);
hash_t toHash();
They should be:
const
{
void print();
string toString();
int opEquals(const(Object) o);
int opCmp(const(Object) o);
hash_t toHash();
}
(And for that matter, opEquals should probably return bool, but that's less important).
And just to make life really interesting, if you do
class A
{
const
{
int opEquals(Object o) { /*...*/ }
}
}
You get the error message
function A.opEquals (Object) does not match parameter types (Object)
Comment #1 by caron800 — 2008-04-25T02:15:54Z
Raising the priority of this to critical because it hasn't been fixed yet.
The following will not compile:
import std.stdio;
class A {}
const A a = new A;
const A b = new A;
void main()
{
if (a == b) writefln("equal");
}
The error is
Error: a.opEquals can only be called on a mutable object, not const(A)
Comment #2 by matti.niemenmaa+dbugzilla — 2008-04-25T04:29:09Z
Please keep the version field as the oldest known affected version.
Comment #3 by caron800 — 2008-04-25T04:55:45Z
On 25/04/2008, [email protected] <[email protected]> wrote:
> Please keep the version field as the oldest known affected version.
Sorry. Didn't realise.
Although in this case, the oldest known affected version is, in fact,
every single version of D since const was first introduced. I have no
idea when that was.
J
Comment #4 by dfj1esp02 — 2008-12-01T08:41:47Z
Adding const code duplication bug as dependency, since overrides of these methods can depend on other methods possibly non-const, which will lead to code duplication.
Comment #5 by dfj1esp02 — 2009-02-03T06:22:13Z
Additional note: many classes in object.di are declared with mutable members. Shouldn't ClassInfo, TypeInfo etc. be invariant?
Comment #6 by dfj1esp02 — 2009-05-27T06:22:58Z
*** Issue 3027 has been marked as a duplicate of this issue. ***
Comment #7 by dfj1esp02 — 2009-05-27T06:24:24Z
*** Issue 2899 has been marked as a duplicate of this issue. ***
Comment #8 by post — 2010-06-21T10:44:32Z
As of DMD 2.020, this is a druntime issue, not a Phobos one.
Comment #9 by k.hara.pg — 2011-04-12T03:13:52Z
*** Issue 3916 has been marked as a duplicate of this issue. ***
Comment #10 by schveiguy — 2011-04-12T06:35:27Z
Just a note regarding bug 3916, the issue extends into the global opEquals function for object, it must also be const correct.
Any chance of this being folded in for the upcoming 2.058 release? I am working on porting my libraries to D2, and it would be good to have this done and dusted so that I don't have to work around it.
Comment #13 by schveiguy — 2012-02-08T10:24:14Z
(In reply to comment #12)
> Any chance of this being folded in for the upcoming 2.058 release?
Likely not. I think only fixing regressions is allowed right now.
Comment #14 by bugzilla — 2012-02-08T12:40:03Z
I intend to deal with this at the beginning of the next release cycle. It is a disruptive change.
Comment #15 by smjg — 2012-04-08T10:23:47Z
(In reply to comment #14)
> I intend to deal with this at the beginning of the next release cycle. It is a
> disruptive change.
Still no sign of it in the 2.059 fix list that has just appeared on the site. Where are you at with it at the moment?
Comment #16 by bugzilla — 2012-04-08T11:32:23Z
(In reply to comment #15)
> Still no sign of it in the 2.059 fix list that has just appeared on the site.
> Where are you at with it at the moment?
It's a pretty disruptive change. There are some significant issues, like toHash in std.stream is very impure. All that needs to be worked out.
Comment #17 by github-bugzilla — 2012-07-08T19:39:59Z