http://d.puremagic.com/issues/show_bug.cgi?id=8099

           Summary: Inner class's outer pointer matches constancy of
                    inner, but can be set to object of arbitrary constancy
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: accepts-invalid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: [email protected]
        ReportedBy: [email protected]
            Blocks: 2573


--- Comment #0 from Stewart Gordon <[email protected]> 2012-05-15 08:16:32 PDT ---
An inner class considers the pointer to the outer object to have the same
constancy as itself.  (This doesn't seem to be stated in the spec, but by
const-transitivity rules it would have to be the same or stronger.  See issue
8098 comment 1.)

Nonetheless, when instantiating the inner class it totally disregards the
constancy of the outer with which it is instantiated.  This means that the
inner class can be viewing a mutable outer object as immutable, or vice versa.

----------
import std.stdio;

class Outer {
    class Inner {}
}

void test(X, Y)(X x, Y y) {
    writefln("%-20s  %-20s  %s", X.stringof, Y.stringof,
typeof(y.outer).stringof);
}

void main() {
    auto m = new Outer;
    auto c = new const(Outer);
    auto i = new immutable(Outer);

    auto mm = m.new Inner;             test(m, mm);  // m -> m  OK
    auto mc = m.new const(Inner);      test(m, mc);  // m -> c  OK
    auto mi = m.new immutable(Inner);  test(m, mi);  // m -> i  bad

    auto cm = c.new Inner;             test(c, cm);  // c -> m  bad
    auto cc = c.new const(Inner);      test(c, cc);  // c -> c  OK
    auto ci = c.new immutable(Inner);  test(c, ci);  // c -> i  bad

    auto im = i.new Inner;             test(i, im);  // i -> m  bad
    auto ic = i.new const(Inner);      test(i, ic);  // i -> c  OK
    auto ii = i.new immutable(Inner);  test(i, ii);  // i -> i  OK
}
----------
C:\Users\Stewart\Documents\Programming\D\Tests>inner_const_2
Outer                 Inner                 Outer
Outer                 const(Inner)          const(Outer)
Outer                 immutable(Inner)      immutable(Outer)
const(Outer)          Inner                 Outer
const(Outer)          const(Inner)          const(Outer)
const(Outer)          immutable(Inner)      immutable(Outer)
immutable(Outer)      Inner                 Outer
immutable(Outer)      const(Inner)          const(Outer)
immutable(Outer)      immutable(Inner)      immutable(Outer)
----------
(DMD 2.059 Win32)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to