[Issue 3731] New: Immutable class may be changed when inherits from mutable parent
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Jan 20 12:44:49 PST 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3731
Summary: Immutable class may be changed when inherits from
mutable parent
Product: D
Version: 2.039
Platform: x86
OS/Version: Windows
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: tomeksowi at gmail.com
--- Comment #0 from Tomasz Sowiński <tomeksowi at gmail.com> 2010-01-20 12:44:48 PST ---
This merrily compiles:
class Zmienna {
int a;
this(int a) {
this.a = a;
}
}
immutable class Stala : Zmienna {
this(int a) {
super(a);
}
}
void main() {
auto st = new Stala(5);
Zmienna zm = st;
zm.a = 666;
// st.a = 666; // fails
assert (st.a == 666);
}
The above shows that an immutable class shouldn't be allowed to derive from
mutable classes. Unfortunately it won't work because Object is not (and can't
be) immutable. Not sure how to bite this one, perhaps make an opt out that says
mutable parents with no fields are OK? Or an exception only for Object?
--
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