Skip to content
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

Support for protected members in classes #688

Merged
merged 6 commits into from
Sep 19, 2014
Merged

Conversation

ahejlsberg
Copy link
Member

This change adds support for protected members in classes as proposed in #1. Also, this change introduces better error messages for assignability and subtype checks involving private and optional properties.

Protected members are modeled after C# and Java. Protected members can be accessed only within the declaring class and subclasses of the declaring class. Furthermore, access to a protected instance member is required to take place through an instance of the enclosing class type or a class type constructed from it (this prevents "sibling" class access).

Protected members can be made public in derived classes. Similar to private members, constructors and signature members cannot be protected.

I will follow up with a more formal specification of the rules but wanted to put up the code for folks to experiment with.

Update: Formal specification provided in #700.

Debug.assert(sourceProp);
if (!targetProp) {
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm glad we are getting rid of this check

@sophiajt
Copy link
Contributor

Result from the design meeting:

Everyone is for adding 'protected'. We'd like to get this in.

ahejlsberg added a commit that referenced this pull request Sep 19, 2014
Support for protected members in classes
@ahejlsberg ahejlsberg merged commit 7cc6bbb into master Sep 19, 2014
@ahejlsberg ahejlsberg deleted the protectedMembers branch September 19, 2014 21:45
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants