-
-
Notifications
You must be signed in to change notification settings - Fork 613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A private
class member functions should not be final
implicitly
#20818
Comments
It would break the contract of |
It doesn't make any sense for private to be override just because its in the same module. |
|
Yes, private applies to the module. So what about a subclass outside of the module? Would you argue that the overridden function should then be private to the subclass's module? That seems incredibly unintuitive, as it's then not really private-to-the-module. Or would you argue that overriding outside of the module should be an error? That makes more sense, but it's still a massively breaking change for very little gain. |
Yes, you can’t override what you can’t see. Outside the module, it’s not visible, ergo you can’t override it. To me, that was completely obvious.
Is it a breaking change? IIUC, it does affect the ABI because the vtable changes, but it could be done in a new edition. I don’t know if it’s that big of a deal since altering
A |
No, a protected member, isn't essentially public, as you can't access it outside the class outside the module, while with public you certainly can. Protected and public is not the same thing! A better solution is to allow writing this:
|
Pattern that this rule makes impossible:
In D,
private
restricts visibility to the module, not the class. Accessing a private member of a class outside of it is trivial and meaningful. This is something that should “obviously work” as soon as one understands whatprivate
means in D. The rule thatprivate
impliesfinal
probably stems from C++ and Java, whereprivate
restricts visibility to the class. Aprivate
member function can be madefinal
by the optimizer if it is determined that it’s not actually overridden.A workaround is to put the module in its own package and make the members
package
.The text was updated successfully, but these errors were encountered: