If a method of a class returns a const or immutable value, and
the class has class invariant, then the compile fails. It also
fails if a method returning a const/immutable has an out contract.
The following code:
--------------------
class Foo
{
invariant() {}
const(int) foo()
{
return 0;
}
immutable(int) bar()
out(abc) { }
body
{
return 0;
}
}
--------------------
causes this compile error:
--------------------
test.d(4): Error: variable test.Foo.foo.__result cannot modify const
test.d(9): Error: variable test.Foo.bar.abc cannot modify mutable
--------------------
Comment #1 by rsinfu — 2009-05-10T15:17:32Z
Created attachment 356
This patch should fix the problem.
Comment #2 by dfj1esp02 — 2009-06-04T01:07:00Z
*** Issue 3048 has been marked as a duplicate of this issue. ***
Comment #3 by dfj1esp02 — 2009-06-10T02:35:19Z
*** Issue 2799 has been marked as a duplicate of this issue. ***
Comment #4 by clugdbug — 2010-05-14T12:29:43Z
On svn 484(DMD 2.046), this patch doesn't fix the test case. It's possible that the patch will work once bug 3667 is fixed, but I haven't tested that.
Comment #5 by clugdbug — 2010-06-05T03:47:28Z
Fixed when bug 3667 was fixed, in svn 490 (DMD 2.047).