Protected module members -- regression?

Steven Schveighoffer schveiguy at gmail.com
Mon Oct 29 15:45:16 UTC 2018


On 10/29/18 6:37 AM, Mike Parker wrote:
> I've long had it in my mind to do a sort of "D for C++/Java/C#" 
> programmers sort of series on the blog. Inspired by the recent 
> conversation about private-to-the-module, I started one on that topic. 
> Then I encountered this:
> 
> ```
> module a;
> 
> protected int wrong;
> ```
> 
> ```
> module b;
> import std.stdio;
> import a;
> 
> int main() { writeln(wrong); }
> ```
> 
> I've always understood that protected module members are illegal. The 
> docs explicitly say so. Yet the declaration of `wrong` compiles. 
> Instead, trying to use it results in the deprecation message about 
> symbol visibility that was added a couple years back when access 
> modifiers were incorporated into symbol lookup.
> 
> I assume this is a regression and filed it as such [1], but I'm curious 
> if the compiler has ever actually complained about protected module 
> members.
> 
> [1] https://issues.dlang.org/show_bug.cgi?id=19340

D has a history of ignoring inapplicable attributes. I would expect this 
is probably the same thing.

for example:

pure int x;

The reason (I think) is that you sometimes put attribute: for a bunch of 
things, or attribute { ... } and it would be super-annoying if you got 
complaints about using illegal attributes for some of the items, when 
you really just wanted them to apply to others. I think internally, the 
attribute label, attribute scope, and plain attributes are implemented 
the same way, so it *may* be hard to split out the single attributes 
from others. But this is entirely conjecture, as I have no idea how it's 
actually implemented :)

-Steve


More information about the Digitalmars-d mailing list