[Issue 2933] New: Cannot return const/immutable with contracts (out/invariant) enabled
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun May 3 23:26:01 PDT 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2933
Summary: Cannot return const/immutable with contracts
(out/invariant) enabled
Product: D
Version: 2.029
Platform: PC
OS/Version: Windows
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: bugzilla at digitalmars.com
ReportedBy: tekjig at gmail.com
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
--------------------
--
More information about the Digitalmars-d-bugs
mailing list