[Issue 8998] New: 'inout pure' returns immutable, which in reality is mutable
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Nov 11 15:25:22 PST 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8998
Summary: 'inout pure' returns immutable, which in reality is
mutable
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P3
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: acehreli at yahoo.com
--- Comment #0 from Ali Cehreli <acehreli at yahoo.com> 2012-11-11 15:25:20 PST ---
class A
{
int i;
}
class C
{
A a;
this()
{
a = new A();
}
// WRONG: Returns immutable(A)
immutable(A) get() inout pure
{
return a;
}
}
void main()
{
auto c = new C;
immutable(A) imm_a = c.get();
assert(imm_a.i == 0);
c.a.i = 100; // <-- changes immutable(A)
assert(imm_a.i == 100); // <-- Oops!
}
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list