July 14, 2008 [Issue 2225] New: accessing private declaration allowed | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=2225 Summary: accessing private declaration allowed Product: D Version: 1.031 Platform: PC OS/Version: Windows Status: NEW Keywords: accepts-invalid Severity: normal Priority: P2 Component: DMD AssignedTo: bugzilla@digitalmars.com ReportedBy: davidl@126.com a.d module a; import b; int bar() { Outer o = new Outer; o.a = 3; Outer.Inner oi = o.new Inner; return oi.foo(); // returns 3 } b.d module b; class Outer { int a; private: class Inner { int foo() { return a; } } } -- |
July 14, 2008 Re: [Issue 2225] New: accessing private declaration allowed | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | <d-bugmail@puremagic.com> wrote in message news:bug-2225-3@http.d.puremagic.com/issues/... > http://d.puremagic.com/issues/show_bug.cgi?id=2225 > > Summary: accessing private declaration allowed > Product: D > Version: 1.031 > Platform: PC > OS/Version: Windows > Status: NEW > Keywords: accepts-invalid > Severity: normal > Priority: P2 > Component: DMD > AssignedTo: bugzilla@digitalmars.com > ReportedBy: davidl@126.com > > > a.d > module a; > import b; > int bar() > { > Outer o = new Outer; > o.a = 3; > Outer.Inner oi = o.new Inner; > return oi.foo(); // returns 3 > } > > b.d > module b; > class Outer > { > int a; > private: > class Inner > { > int foo() > { > return a; > } > } > } > So, what's the bug? The language has never prevented you from accessing private classes/structs. I don't think it's ever mentioned in the spec. I will, however agree that it _should_ error on this (cannot access private class Inner), making this an enhancement request. If you're expecting foo() to be private, I don't think that's how it works. |
Copyright © 1999-2021 by the D Language Foundation