digitalmars.dip.ideas - Protected visiblity expansion
- Richard (Rikki) Andrew Cattermole (65/65) Dec 01 Here is an idea to satisfy a lot of people: upgrading the
- claptrap (3/68) Dec 02 You stole me idea!
- jmh530 (6/32) Dec 02 Sorry if this is obvious to you, but I can't recall ever writing
- Richard (Rikki) Andrew Cattermole (4/44) Dec 02 https://dlang.org/spec/attribute.html#protected
- jmh530 (4/16) Dec 02 I read that text like 5 times before I posted and it still is a
Here is an idea to satisfy a lot of people: upgrading the
protected visibility modifier to include a symbol.
The default is to use the this pointer or the current module.
```d
module a;
protected void freeFunc() {
}
class Class {
protected void method() {
}
}
```
```d
module b;
import a;
void main() {
freeFunc; // error
class Child : Class {
this() {
this.method; // ok
}
}
Child child = new Child;
child.method; // error
}
```
If we provide it a symbol or module/package it'll limit to all
symbols below that.
```d
module pack.a;
protected(pack.b.check) void freeFunc() {
}
class Class {
protected(pack.b.check) void method() {
}
}
```
```d
module b;
import a;
void main() {
freeFunc; // error
class Child : Class {
this() {
this.method; // error
}
}
Child child = new Child;
child.method; // error
}
void check() {
freeFunc; // ok
class Child : Class {
this() {
this.method; // ok
}
}
Child child = new Child;
child.method; // ok
}
```
To spice it up one more level, let's also make it accept multiple
symbols.
That should cover pretty much every hole in visibility modifiers
that people could dream up!
Dec 01
On Monday, 1 December 2025 at 22:30:56 UTC, Richard (Rikki)
Andrew Cattermole wrote:
Here is an idea to satisfy a lot of people: upgrading the
protected visibility modifier to include a symbol.
The default is to use the this pointer or the current module.
```d
module a;
protected void freeFunc() {
}
class Class {
protected void method() {
}
}
```
```d
module b;
import a;
void main() {
freeFunc; // error
class Child : Class {
this() {
this.method; // ok
}
}
Child child = new Child;
child.method; // error
}
```
If we provide it a symbol or module/package it'll limit to all
symbols below that.
```d
module pack.a;
protected(pack.b.check) void freeFunc() {
}
class Class {
protected(pack.b.check) void method() {
}
}
```
```d
module b;
import a;
void main() {
freeFunc; // error
class Child : Class {
this() {
this.method; // error
}
}
Child child = new Child;
child.method; // error
}
void check() {
freeFunc; // ok
class Child : Class {
this() {
this.method; // ok
}
}
Child child = new Child;
child.method; // ok
}
```
To spice it up one more level, let's also make it accept
multiple symbols.
That should cover pretty much every hole in visibility
modifiers that people could dream up!
You stole me idea!
Dec 02
On Monday, 1 December 2025 at 22:30:56 UTC, Richard (Rikki)
Andrew Cattermole wrote:
Here is an idea to satisfy a lot of people: upgrading the
protected visibility modifier to include a symbol.
The default is to use the this pointer or the current module.
```d
module a;
protected void freeFunc() {
}
class Class {
protected void method() {
}
}
```
```d
module b;
import a;
void main() {
freeFunc; // error
class Child : Class {
this() {
this.method; // ok
}
}
Child child = new Child;
child.method; // error
}
```
Sorry if this is obvious to you, but I can't recall ever writing
code with protected in it. Shouldn't child.method not be an error
under the current rules since you are accessing it through the
derived class?
Dec 02
On 03/12/2025 12:27 AM, jmh530 wrote:On Monday, 1 December 2025 at 22:30:56 UTC, Richard (Rikki) Andrew Cattermole wrote:https://dlang.org/spec/attribute.html#protected You can only access inside the derived class, or in its original module that defined the method.Here is an idea to satisfy a lot of people: upgrading the protected visibility modifier to include a symbol. The default is to use the this pointer or the current module. ```d module a; protected void freeFunc() { } class Class { protected void method() { } } ``` ```d module b; import a; void main() { freeFunc; // error class Child : Class { this() { this.method; // ok } } Child child = new Child; child.method; // error } ```Sorry if this is obvious to you, but I can't recall ever writing code with protected in it. Shouldn't child.method not be an error under the current rules since you are accessing it through the derived class?
Dec 02
On Tuesday, 2 December 2025 at 21:20:52 UTC, Richard (Rikki) Andrew Cattermole wrote:On 03/12/2025 12:27 AM, jmh530 wrote:I read that text like 5 times before I posted and it still is a little tricky.On Monday, 1 December 2025 at 22:30:56 UTC, Richard (Rikki) Andrew Cattermole wrote:https://dlang.org/spec/attribute.html#protected You can only access inside the derived class, or in its original module that defined the method.[...]Sorry if this is obvious to you, but I can't recall ever writing code with protected in it. Shouldn't child.method not be an error under the current rules since you are accessing it through the derived class?
Dec 02









claptrap <clap trap.com> 