Fixes #18240 - "Generate class ..." causes inconsistent accessibility#18455
Fixes #18240 - "Generate class ..." causes inconsistent accessibility#18455sharwell merged 4 commits intodotnet:masterfrom d0pare:master
Conversation
|
😎 Welcome to the project! |
|
Thank you 😄 |
There was a problem hiding this comment.
💡 Another good test would be the following. Unlike other types, if you omit the accessibility keyword from an interface member (which is actually a requirement in this location), the result is effectively public instead of private.
public interface A
{
void B<T>() where T : D;
}There was a problem hiding this comment.
Nit: Parameters should be indented 4 past private here.
There was a problem hiding this comment.
Nit: space after // and use Sentence case for comments.
There was a problem hiding this comment.
Sentence case, and rationalize with the numbering in the rest of the comments in this method.
There was a problem hiding this comment.
Consider: Switching the sense of this and renaming to something like: AllContainingTypesArePublic.
There was a problem hiding this comment.
Related to @sharwell's comment - what is DeclaredAccessibility for interface members?
sharwell
left a comment
There was a problem hiding this comment.
I don't see any red flags here. I'm requesting a second review from @CyrusNajmabadi or someone else who's more familiar with the nuances of the extension methods you modified.
I noticed some small things which fall into a category of "I would typically just fix these when I merged the pull request":
- The indentation has some discrepancies in a couple places. Also there are two cases where a space is missing after the keyword in
foreach(andif(. - The tests cover many cases, but there are a few remaining. Considering how many cases were missing from the original code it's hard to complain here. 😆
I notice that only one of two available code fixes gets tested. I'm assuming this is due to a limitation in the test infrastructure where it's somewhere between non-trivial and impossible to test code fixes that affect other files. When I was working on StyleCop Analyzers, we faced a similar situation for a long time. Eventually @otac0n figured out a way to test these cases in DotNetAnalyzers/StyleCopAnalyzers#2140, but assuming it's not already in place we're talking about a lot of work down in the depths of the test infrastructure to implement something similar here.
|
Created new commit (will squash at the merge hopefully 😄) for requested action items from code review. |
Pilchie
left a comment
There was a problem hiding this comment.
Thanks for the style fixes. LGTM, but I'd love @CyrusNajmabadi to take a quick look too.
|
Squashed commits for next review |
There was a problem hiding this comment.
❗️ This one should be internal because Employee is internal. It should only generate a public type here if the interface is also public.
There was a problem hiding this comment.
When can you have a TypeConstraint that is not parented by a TypeParameterConstraintClause?
There was a problem hiding this comment.
I cannot imagine case when TypeConstraint cannot be parented by TypeParameterConstraintClause. Just putted for sanity, will remove it.
There was a problem hiding this comment.
this step does not seem necessary. Can you clarify why you need to do it?
There was a problem hiding this comment.
Same type is passed to DetermineAccessibilityConstraint which has type = GetOutermostType(type);
There was a problem hiding this comment.
My point is this: immediately after you make this call, you then call type.GetAncestors<TypeDeclarationSyntax>(). You then do not use type again. So this call, and the overwriting of 'type' seems unnecessary since it will not affect the results you get from type.GetAncestors<TypeDeclarationSyntax>() :)
There was a problem hiding this comment.
This check doesn't match your method name. For example, you'll return 'true' if one of the containing types i protected.
That may be what you want, but in tha t case the method name should be AllContainingTypesArePublicOrProtected.
There was a problem hiding this comment.
I will disagree because topmost type is either public or internal. Protected can be only in the middle.
There was a problem hiding this comment.
AllContainingTypeAreNotPrivateOrInternal then :)
There was a problem hiding this comment.
Actually, rgd:
I will disagree because topmost type is either public or internal. Protected can be only in the middle.
But you still return false, even if the topmost type is internal. So it's correct to say "AllContainingTypesArePublicOrProtected".
There was a problem hiding this comment.
nit, consider use ? : expression to simplify this.
There was a problem hiding this comment.
new tests shoudl include a [WorkItem(bugnumber, "github-issue-link")] attribute on them.
There was a problem hiding this comment.
📝 For this issue, they'll have this form:
[WorkItem(18240, "https://github.com/dotnet/roslyn/issues/18240")]There was a problem hiding this comment.
this feels strange. Command should not be public here.
There was a problem hiding this comment.
i don't think command should be public here either.
|
Fixed all issues from review |
There was a problem hiding this comment.
nit: try to wrap lines longer than what github can display. our general patter for ?: is
accessibility = AllContainingTypesArePublicOrProtected(state, semanticModel, cancellationToken)
? Accessibility.Public
: Accessibility.Internal;|
Currently investigating vsi failures. Don't read anything into vsi failures for now. |
|
Rebased onto roslyn/master |
|
@dopare This one has been sitting and I'd like to get it prepared for merge. Would you like to handle the updates, or would you like me to "take over" the pull request since it's likely to require more preparation given the amount of time it sat for? |
|
@sharwell Please take over. Currently I don't have enough time to make updates. |
|
approved to merge for 15.8.preview3 |
|
test windows_release_vs-integration_prtest |
|
@dopare Thank you! 😄 |
|
Holy moly, finally 😄 |
Fixes #18240.
Currently if nested class is protected then we generate internal class which can cause compilation error if protected class is under public class.
This PR also fixes that issue.