[Issue 3731] Derived class implicitly convertible to base class with arbitrary change of constancy
http://d.puremagic.com/issues/show_bug.cgi?id=3731 --- Comment #15 from github-bugzi...@puremagic.com 2012-07-18 00:08:12 PDT --- Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/65f12c80d383bd655aec1f53510fd4ae201b3b79 Fix Issue 3731 - Can implicitly cast an immutable reference to a derived class to a mutable reference to a base class. Ensure the modifier conversion is valid before allowing an implicit conversion to a base class. https://github.com/D-Programming-Language/dmd/commit/bf982fac38051e34d365d972ff847983cb73848a Merge pull request #125 from yebblies/issue3731 Issue 3731 - Can implicitly cast an immutable reference to a derived class -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 3731] Derived class implicitly convertible to base class with arbitrary change of constancy
http://d.puremagic.com/issues/show_bug.cgi?id=3731 Don clugd...@yahoo.com.au changed: What|Removed |Added Status|NEW |RESOLVED CC||clugd...@yahoo.com.au Resolution||FIXED -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 3731] Derived class implicitly convertible to base class with arbitrary change of constancy
http://d.puremagic.com/issues/show_bug.cgi?id=3731 Steven Schveighoffer schvei...@yahoo.com changed: What|Removed |Added CC||jmdavisp...@gmx.com --- Comment #14 from Steven Schveighoffer schvei...@yahoo.com 2012-04-19 04:52:11 PDT --- *** Issue 7939 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: ---
[Issue 3731] Derived class implicitly convertible to base class with arbitrary change of constancy
http://d.puremagic.com/issues/show_bug.cgi?id=3731 Steven Schveighoffer schvei...@yahoo.com changed: What|Removed |Added CC||d...@me.com --- Comment #13 from Steven Schveighoffer schvei...@yahoo.com 2012-04-16 05:30:03 PDT --- *** Issue 7920 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: ---
[Issue 3731] Derived class implicitly convertible to base class with arbitrary change of constancy
http://d.puremagic.com/issues/show_bug.cgi?id=3731 --- Comment #10 from Steven Schveighoffer schvei...@yahoo.com 2012-03-26 03:11:50 PDT --- (In reply to comment #9) (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. I think you misunderstand. I don't mean because Stala exists, Zmienna should be prevented from being mutable, even for cases where Stala is not involved. I mean, it should be illegal to have a mutable Stala reference point at a Zmienna. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 3731] Derived class implicitly convertible to base class with arbitrary change of constancy
http://d.puremagic.com/issues/show_bug.cgi?id=3731 --- Comment #11 from Stewart Gordon s...@iname.com 2012-03-26 03:57:16 PDT --- (In reply to comment #10) I think you misunderstand. I don't mean because Stala exists, Zmienna should be prevented from being mutable, even for cases where Stala is not involved. I mean, it should be illegal to have a mutable Stala reference point at a Zmienna. I haven't misunderstood. There's no such thing as a mutable Stala reference. Because Stala is an immutable class, any reference to a Stala is automatically immutable. See for yourself: - void main() { Stala st = new Stala(5); pragma(msg, typeof(st)); // immutable(Stala) st = new Stala(4);// errors, because st is immutable Zmienna zm = st; // accepts-invalid } - The bug is that DMD allows the implicit conversion of immutable(Stala) to Zmienna. It's just mb_id in my last example. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 3731] Derived class implicitly convertible to base class with arbitrary change of constancy
http://d.puremagic.com/issues/show_bug.cgi?id=3731 Stewart Gordon s...@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 s...@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() { Derivedmd; 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: ---