Thread overview | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
January 20, 2010 [Issue 3731] New: Immutable class may be changed when inherits from mutable parent | ||||
---|---|---|---|---|
| ||||
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@puremagic.com ReportedBy: tomeksowi@gmail.com --- Comment #0 from Tomasz Sowiński <tomeksowi@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: ------- |
January 21, 2010 [Issue 3731] Immutable class may be changed when inherits from mutable parent | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tomasz Sowiński | http://d.puremagic.com/issues/show_bug.cgi?id=3731 Steven Schveighoffer <schveiguy@yahoo.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |schveiguy@yahoo.com --- Comment #1 from Steven Schveighoffer <schveiguy@yahoo.com> 2010-01-21 05:43:28 PST --- The solution would be to make it illegal to have a mutable class reference to the base class. In your example, this line should be an error: Zmienna zm = st; // error, must use immutable(Zmienna) or const(Zmienna) -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
January 21, 2010 [Issue 3731] Immutable class may be changed when inherits from mutable parent | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tomasz Sowiński | http://d.puremagic.com/issues/show_bug.cgi?id=3731 --- Comment #2 from Tomasz Sowiński <tomeksowi@gmail.com> 2010-01-21 11:03:00 PST --- (In reply to comment #1) > The solution would be to make it illegal to have a mutable class reference to the base class. > > In your example, this line should be an error: > > Zmienna zm = st; // error, must use immutable(Zmienna) or const(Zmienna) Thanks, that makes sense. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
June 14, 2011 [Issue 3731] Can implicitly cast an immutable reference to a derived class | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tomasz Sowiński | http://d.puremagic.com/issues/show_bug.cgi?id=3731 yebblies <yebblies@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |accepts-invalid, patch CC| |yebblies@gmail.com Summary|Immutable class may be |Can implicitly cast an |changed when inherits from |immutable reference to a |mutable parent |derived class --- Comment #3 from yebblies <yebblies@gmail.com> 2011-06-13 22:59:03 PDT --- https://github.com/D-Programming-Language/dmd/pull/125 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
September 16, 2011 [Issue 3731] Can implicitly cast an immutable reference to a derived class | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tomasz Sowiński | http://d.puremagic.com/issues/show_bug.cgi?id=3731 --- Comment #4 from Kenji Hara <k.hara.pg@gmail.com> 2011-09-16 03:24:37 PDT --- I think issue 3731 is same as issue 5080, and the yebblies patch is a bit better than mine. See also Don and Steven's comments in 5080. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
December 13, 2011 [Issue 3731] Can implicitly cast an immutable reference to a derived class | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tomasz Sowiński | http://d.puremagic.com/issues/show_bug.cgi?id=3731 yebblies <yebblies@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |rayerd.wiz@gmail.com --- Comment #5 from yebblies <yebblies@gmail.com> 2011-12-13 16:23:28 EST --- *** Issue 6863 has been marked as a duplicate of this issue. *** -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
January 28, 2012 [Issue 3731] Can implicitly cast an immutable reference to a derived class | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tomasz Sowiński | http://d.puremagic.com/issues/show_bug.cgi?id=3731 --- Comment #6 from github-bugzilla@puremagic.com 2012-01-27 20:24:11 PST --- Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/7bed81961aefc5327b57be0862514b78d84355db The fix for issue 3731 shows a couple of places in phobos that rely on this bug. std.xml is going away, so work around the issue for now (all problems are caused by opEquals and opCmp not being const correct) and in std.datetime, AA values must be rebindable. https://github.com/D-Programming-Language/phobos/commit/472c2a984391a97fd6fda5b77d082e184b828c87 Merge pull request #408 from yebblies/issue3731 Remove implicit casts to mutable super class -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
January 31, 2012 [Issue 3731] Can implicitly cast an immutable reference to a derived class | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tomasz Sowiński | http://d.puremagic.com/issues/show_bug.cgi?id=3731 yebblies <yebblies@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |k.hara.pg@gmail.com --- Comment #7 from yebblies <yebblies@gmail.com> 2012-01-31 13:13:15 EST --- *** Issue 5080 has been marked as a duplicate of this issue. *** -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
March 04, 2012 [Issue 3731] Can implicitly cast an immutable reference to a derived class | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tomasz Sowiński | http://d.puremagic.com/issues/show_bug.cgi?id=3731 dawg@dawgfoto.de changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |dawg@dawgfoto.de --- Comment #8 from dawg@dawgfoto.de 2012-03-04 05:19:41 PST --- *** Issue 7636 has been marked as a duplicate of this issue. *** -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
March 25, 2012 [Issue 3731] Derived class implicitly convertible to base class with arbitrary change of constancy | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tomasz Sowiński | http://d.puremagic.com/issues/show_bug.cgi?id=3731 Stewart Gordon <smjg@iname.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|Can implicitly cast an |Derived class implicitly |immutable reference to a |convertible to base class |derived class |with arbitrary change of | |constancy --- Comment #9 from Stewart Gordon <smjg@iname.com> 2012-03-25 07:52:59 PDT --- (In reply to comment #1) > The solution would be to make it illegal to have a mutable class reference to the base class. No, because a Zmienna is perfectly allowed to be mutable. It's Stala that isn't. > In your example, this line should be an error: > > Zmienna zm = st; // error, must use immutable(Zmienna) or const(Zmienna) Correct, since because Stala is immutable, any object reference of type Stala is actually of type immutable(Stala). The bug is that constancy is ignored when converting from a derived class to a base class, as this code shows (DMD 2.058, Win32): ---------- class Base { int x; } class Derived : Base { int y; } void main() { Derived md; const(Derived) cd; immutable(Derived) id; Base mb_md = md; const(Base) cb_md = md; immutable(Base) ib_md = md; // accepts-invalid Base mb_cd = cd; // accepts-invalid const(Base) cb_cd = cd; immutable(Base) ib_cd = cd; // accepts-invalid Base mb_id = id; // accepts-invalid const(Base) cb_id = id; immutable(Base) ib_id = id; } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation