June 13, 2022
On Monday, 13 June 2022 at 08:07:05 UTC, Mike Parker wrote:
>
> But why should that compile? You're trying to manipulate `_c` through an instance of `Bar`. It's not visible in any `Bar`, ever, so why should it be visible here? It has to be gotten at through the interface of `Foo`.

Because I'm in the module of a, _c is a member if Foo, Foo is in a.

Thus _c should be accessible within a regardless of whether it's public within the b module or not.
June 13, 2022

On Monday, 13 June 2022 at 08:13:14 UTC, claptrap wrote:

>

On Sunday, 12 June 2022 at 14:05:00 UTC, Max Samukha wrote:

>

On Sunday, 12 June 2022 at 11:47:53 UTC, Mike Parker wrote:

>

Hi. My name's Mike. Nice to meet you.

Hi, Mike! Congratulations on being the first unsurprised D user! (You were actually surprised for a moment, weren't you?)

Anyone who used Object Pascal / Delphi wouldn't have been surprised either.

I am a narrow-minded person and have never written a line in those. However, I heard that the original author of Turbo Pascal eventually did a reasonable thing with C#, which has the class-level 'private' and 'internal' to break out if it.

June 13, 2022
On Monday, 13 June 2022 at 08:44:59 UTC, bauss wrote:
> On Monday, 13 June 2022 at 08:07:05 UTC, Mike Parker wrote:
>>
>> But why should that compile? You're trying to manipulate `_c` through an instance of `Bar`. It's not visible in any `Bar`, ever, so why should it be visible here? It has to be gotten at through the interface of `Foo`.
>
> Because I'm in the module of a, _c is a member if Foo, Foo is in a.
>
> Thus _c should be accessible within a regardless of whether it's public within the b module or not.

My argument for why it should work is that if you place the subclass within the same module then it works, so clearly it's just a matter of where the function was called, not where it resides.
June 13, 2022

On Monday, 13 June 2022 at 08:47:29 UTC, Max Samukha wrote:

>

class-level 'private' and 'internal' to break out if it.

*out of it

June 13, 2022
On Monday, 13 June 2022 at 08:49:18 UTC, bauss wrote:
> On Monday, 13 June 2022 at 08:44:59 UTC, bauss wrote:
>> On Monday, 13 June 2022 at 08:07:05 UTC, Mike Parker wrote:
>>>
>>> But why should that compile? You're trying to manipulate `_c` through an instance of `Bar`. It's not visible in any `Bar`, ever, so why should it be visible here? It has to be gotten at through the interface of `Foo`.
>>
>> Because I'm in the module of a, _c is a member if Foo, Foo is in a.
>>
>> Thus _c should be accessible within a regardless of whether it's public within the b module or not.
>
> My argument for why it should work is that if you place the subclass within the same module then it works, so clearly it's just a matter of where the function was called, not where it resides.

Actually I could have worded this better, but hopefully my point comes across.
June 13, 2022

On Monday, 13 June 2022 at 08:44:59 UTC, bauss wrote:

>

Thus _c should be accessible within a regardless of whether it's public within the b module or not.

Yes, I agree. It should not matter whether the pointer is typed as Foo or Bar, as a Bar is also a Foo.

June 13, 2022

On Monday, 13 June 2022 at 08:59:24 UTC, Ola Fosheim Grøstad wrote:

>

On Monday, 13 June 2022 at 08:44:59 UTC, bauss wrote:

>

Thus _c should be accessible within a regardless of whether it's public within the b module or not.

Yes, I agree. It should not matter whether the pointer is typed as Foo or Bar, as a Bar is also a Foo.

Exactly.

I'm all for it being illegal, but then D isn't "module private" and stating it is would be wrong then.

June 13, 2022
On Monday, 13 June 2022 at 08:49:18 UTC, bauss wrote:

> My argument for why it should work is that if you place the subclass within the same module then it works, so clearly it's just a matter of where the function was called, not where it resides.

I don't get why you expect it to work. If you declare `Bar` outside of the module, then how could you access the private members of `Foo` through a `Bar`? It works in the same module because... private to the module.
June 13, 2022

On Monday, 13 June 2022 at 08:13:14 UTC, claptrap wrote:

>

On Sunday, 12 June 2022 at 14:05:00 UTC, Max Samukha wrote:

>

On Sunday, 12 June 2022 at 11:47:53 UTC, Mike Parker wrote:

>

Hi. My name's Mike. Nice to meet you.

Hi, Mike! Congratulations on being the first unsurprised D user! (You were actually surprised for a moment, weren't you?)

Anyone who used Object Pascal / Delphi wouldn't have been surprised either.

True but ObjFPC has strict private too since a while: demo.
This does exactly what is discussed on the D forum since a week.

June 13, 2022

On Monday, 13 June 2022 at 09:05:43 UTC, Mike Parker wrote:

>

On Monday, 13 June 2022 at 08:49:18 UTC, bauss wrote:

>

My argument for why it should work is that if you place the subclass within the same module then it works, so clearly it's just a matter of where the function was called, not where it resides.

I don't get why you expect it to work. If you declare Bar outside of the module, then how could you access the private members of Foo through a Bar? It works in the same module because... private to the module.

It follows from the principles of inheritance. A Bar is a more detailed Foo. If you cannot interact with a Bar as you would with a Foo, then Bar is breaking with the core principles of inheritance. A pointer to Foo, just means that you can assume less about it than if you had a pointer to Bar. If you can assume more about a pointer to a Foo than a pointer to a Bar then something is wrong.