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

Disallow implicit implementation of non-public interface members and explicit implementation of inaccessible members. #19549

Conversation

AlekseyTs
Copy link
Contributor

@dotnet/roslyn-compiler Please review.

…explicit implementation of inaccessible members.
@AlekseyTs
Copy link
Contributor Author

@dotnet/roslyn-compiler Please review.

case SymbolKind.Property:
var propertySymbol = (PropertySymbol)symbol;

bool AccessorIsNotPublic(MethodSymbol accessor)
Copy link
Member

Choose a reason for hiding this comment

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

Consider moving out of the switch statement, since used by both cases.
Also, consider using lower-case (accessorIsNotPublic) for local function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Both were intentional choices. I prefer to keep them unless they violate some guidelines.


In reply to: 116834659 [](ancestors = 116834659)

Copy link
Member

Choose a reason for hiding this comment

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

I agree with @jcouv . Calling a method declared in one switch branch from another switch branch makes the code confusing to read.

@jcouv
Copy link
Member

jcouv commented May 16, 2017

    /// <param name="interfaceMember">A non-null property on an interface type.</param>

Consider updating the comment. This method works on methods, properties and events, not just properties.


Refers to: src/Compilers/CSharp/Portable/Symbols/TypeSymbol.cs:778 in 7d4e4e3. [](commit_id = 7d4e4e3, deletion_comment = False)

@AlekseyTs
Copy link
Contributor Author

    /// <param name="interfaceMember">A non-null property on an interface type.</param>

Consider updating the comment. This method works on methods, properties and events, not just properties.

Done.


In reply to: 301890039 [](ancestors = 301890039)


Refers to: src/Compilers/CSharp/Portable/Symbols/TypeSymbol.cs:778 in 7d4e4e3. [](commit_id = 7d4e4e3, deletion_comment = False)

@AlekseyTs
Copy link
Contributor Author

@dotnet/roslyn-compiler Please review.

@jcouv
Copy link
Member

jcouv commented May 17, 2017

        void ValidateEventNotImplemented_11(CSharpCompilation compilation, string className)

Having a method and a local function with the same name is rather confusing.
Their logic seems the same (except for hard-coded "Test2"), so one can be deleted.


Refers to: src/Compilers/CSharp/Test/Symbol/Symbols/DefaultInterfaceImplementationTests.cs:20047 in 3a44513. [](commit_id = 3a44513, deletion_comment = False)

@AlekseyTs
Copy link
Contributor Author

        void ValidateEventNotImplemented_11(CSharpCompilation compilation, string className)

Yes, meant to delete this function after extracting. Done.


In reply to: 302177324 [](ancestors = 302177324)


Refers to: src/Compilers/CSharp/Test/Symbol/Symbols/DefaultInterfaceImplementationTests.cs:20047 in 3a44513. [](commit_id = 3a44513, deletion_comment = False)

@gafter gafter self-assigned this May 17, 2017
@AlekseyTs
Copy link
Contributor Author

@dotnet/roslyn-compiler Please review.

1 similar comment
@AlekseyTs
Copy link
Contributor Author

@dotnet/roslyn-compiler Please review.

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

LGTM
Sorry, I'd forgotten to approve after reviewing yesterday.

case SymbolKind.Property:
var propertySymbol = (PropertySymbol)implementedMember;

void CheckAccessorAccessible(MethodSymbol acessor)
Copy link
Member

Choose a reason for hiding this comment

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

Typo: accessor

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Typo: accessor

Thanks, I'll address it in the next PR.

@cston
Copy link
Member

cston commented May 18, 2017

    public void PropertyModifiers_23_51()

12?


Refers to: src/Compilers/CSharp/Test/Symbol/Symbols/DefaultInterfaceImplementationTests.cs:13304 in 1399384. [](commit_id = 1399384, deletion_comment = False)

@cston
Copy link
Member

cston commented May 18, 2017

LGTM

Copy link
Member

@gafter gafter left a comment

Choose a reason for hiding this comment

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

Partial review. I did not review the tests yet.

@@ -5076,4 +5076,7 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<data name="ERR_DefaultInterfaceImplementationModifier" xml:space="preserve">
<value>The modifier '{0}' is not valid for this item in C# {1}. Please use language version {2} or greater.</value>
</data>
<data name="ERR_ImplicitImplementationOfNonPublicInterfaceMember" xml:space="preserve">
<value>'{0}' does not implement interface member '{1}'. '{2}' cannot implicitly implement '{1}' because '{1}' is not public.</value>
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be a good idea to find a way to reword this so that fill-ins are not repeated. I think the second sentence can be replaced by "Non-public methods of an interface may not be implemented implicitly."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think there is a value in the second sentence. How about I change it to "'{2}' cannot implicitly implement non-public member" ?

case SymbolKind.Property:
var propertySymbol = (PropertySymbol)symbol;

bool AccessorIsNotPublic(MethodSymbol accessor)
Copy link
Member

Choose a reason for hiding this comment

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

I agree with @jcouv . Calling a method declared in one switch branch from another switch branch makes the code confusing to read.

case SymbolKind.Property:
var propertySymbol = (PropertySymbol)implementedMember;

void CheckAccessorAccessible(MethodSymbol acessor)
Copy link
Member

Choose a reason for hiding this comment

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

Please move this local function out of the switch since it is used in more than one case block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please move this local function out of the switch since it is used in more than one case block.

Will do.

//if we haven't found a match, do a weaker comparison that ignores static-ness, accessibility, and return type
if ((object)closeMismatch == null && implementingTypeIsFromSomeCompilation)
// If we haven't found a match, do a weaker comparison that ignores static-ness, accessibility, and return type.
// But do this only if interface member is public because language doesn't allow implicit implementations for
Copy link
Member

Choose a reason for hiding this comment

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

This comment is confusing. "But do this only if interface member is public because language doesn't allow implicit implementations for such members ..."

The language does allow implicit implementations for interface members that are public. Can you please reword?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How does "But do this only if interface member is public because language doesn't allow implicit implementations for non-public members ..." sound?

@AlekseyTs
Copy link
Contributor Author

12?

I intentionally left a gap,in case I need to add more tests in between.

- Move local functions out of switch statement.
- Rename parameter
- Adjust comment
- Adjust error message text
@AlekseyTs AlekseyTs merged commit f030051 into dotnet:features/DefaultInterfaceImplementation May 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants