Thread overview
[Issue 8099] New: Inner class's outer pointer matches constancy of inner, but can be set to object of arbitrary constancy
May 15, 2012
Stewart Gordon
May 25, 2012
Kenji Hara
May 25, 2012
Walter Bright
May 15, 2012
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: nobody@puremagic.com
        ReportedBy: smjg@iname.com
            Blocks: 2573


--- Comment #0 from Stewart Gordon <smjg@iname.com> 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: -------
May 25, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8099


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull
           Platform|x86                         |All
         OS/Version|Windows                     |All


--- Comment #1 from Kenji Hara <k.hara.pg@gmail.com> 2012-05-25 00:27:02 PDT ---
https://github.com/D-Programming-Language/dmd/pull/965

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 25, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8099



--- Comment #2 from github-bugzilla@puremagic.com 2012-05-25 15:13:01 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/6499c5cf306745c799748c9ea733e57c855c5918
fix Issue 8099 - Inner class's outer pointer matches constancy of inner, but
can be set to object of arbitrary constancy

https://github.com/D-Programming-Language/dmd/commit/4c9b4742011f5febd7313fe25672bffa70758597 Merge pull request #965 from 9rnsr/fix8099

Issue 8099 - Inner class's outer pointer matches constancy of inner, but can be set to object of arbitrary constancy

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 25, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8099


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |FIXED


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