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

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-05-15T08:16:00Z
Last change time
2012-05-25T15:25:30Z
Keywords
accepts-invalid, pull
Assigned to
nobody
Creator
smjg
Blocks
2573

Comments

Comment #0 by smjg — 2012-05-15T08:16:32Z
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)
Comment #1 by k.hara.pg — 2012-05-25T00:27:02Z
Comment #2 by github-bugzilla — 2012-05-25T15:13:01Z
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