-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
…explicit implementation of inaccessible members.
@dotnet/roslyn-compiler Please review. |
case SymbolKind.Property: | ||
var propertySymbol = (PropertySymbol)symbol; | ||
|
||
bool AccessorIsNotPublic(MethodSymbol accessor) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
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) |
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) |
@dotnet/roslyn-compiler Please review. |
Having a method and a local function with the same name is rather confusing. Refers to: src/Compilers/CSharp/Test/Symbol/Symbols/DefaultInterfaceImplementationTests.cs:20047 in 3a44513. [](commit_id = 3a44513, deletion_comment = False) |
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) |
@dotnet/roslyn-compiler Please review. |
1 similar comment
@dotnet/roslyn-compiler Please review. |
There was a problem hiding this 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: accessor
There was a problem hiding this comment.
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.
LGTM |
There was a problem hiding this 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> |
There was a problem hiding this comment.
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."
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
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
@dotnet/roslyn-compiler Please review.