Stewart Gordon <> 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 <> 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

> 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:
------- You are receiving this mail because: -------

Reply via email to