Skip to content

Fixes #18240 - "Generate class ..." causes inconsistent accessibility#18455

Merged
sharwell merged 4 commits intodotnet:masterfrom
d0pare:master
Jun 4, 2018
Merged

Fixes #18240 - "Generate class ..." causes inconsistent accessibility#18455
sharwell merged 4 commits intodotnet:masterfrom
d0pare:master

Conversation

@d0pare
Copy link
Copy Markdown

@d0pare d0pare commented Apr 5, 2017

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.

@sharwell sharwell added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label Apr 5, 2017
@sharwell
Copy link
Copy Markdown
Contributor

sharwell commented Apr 5, 2017

😎 Welcome to the project!

@sharwell sharwell self-requested a review April 5, 2017 14:31
@d0pare
Copy link
Copy Markdown
Author

d0pare commented Apr 5, 2017

Thank you 😄

Copy link
Copy Markdown
Contributor

@sharwell sharwell Apr 5, 2017

Choose a reason for hiding this comment

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

💡 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;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: Parameters should be indented 4 past private here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: space after // and use Sentence case for comments.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: 4 spaces, not 3.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sentence case, and rationalize with the numbering in the rest of the comments in this method.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Spelling - typeDeclarations

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: space after foreach

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: space after if

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Consider: Switching the sense of this and renaming to something like: AllContainingTypesArePublic.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Related to @sharwell's comment - what is DeclaredAccessibility for interface members?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It is always public

Copy link
Copy Markdown
Contributor

@sharwell sharwell left a comment

Choose a reason for hiding this comment

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

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":

  1. The indentation has some discrepancies in a couple places. Also there are two cases where a space is missing after the keyword in foreach( and if(.
  2. 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.

@d0pare
Copy link
Copy Markdown
Author

d0pare commented Apr 5, 2017

Created new commit (will squash at the merge hopefully 😄) for requested action items from code review.
Added 2 more tests and renamed new tests' names to more meaningful names.

Copy link
Copy Markdown
Member

@Pilchie Pilchie left a comment

Choose a reason for hiding this comment

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

Thanks for the style fixes. LGTM, but I'd love @CyrusNajmabadi to take a quick look too.

@Pilchie Pilchie requested a review from CyrusNajmabadi April 5, 2017 17:42
@d0pare
Copy link
Copy Markdown
Author

d0pare commented Apr 5, 2017

Squashed commits for next review

Copy link
Copy Markdown
Contributor

@sharwell sharwell Apr 5, 2017

Choose a reason for hiding this comment

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

❗️ This one should be internal because Employee is internal. It should only generate a public type here if the interface is also public.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When can you have a TypeConstraint that is not parented by a TypeParameterConstraintClause?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I cannot imagine case when TypeConstraint cannot be parented by TypeParameterConstraintClause. Just putted for sanity, will remove it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this step does not seem necessary. Can you clarify why you need to do it?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Same type is passed to DetermineAccessibilityConstraint which has type = GetOutermostType(type);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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>() :)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Ah, sorry my bad. Will fix this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No worries :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I will disagree because topmost type is either public or internal. Protected can be only in the middle.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AllContainingTypeAreNotPrivateOrInternal then :)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

sure :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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".

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Got your point.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit, consider use ? : expression to simplify this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

new tests shoudl include a [WorkItem(bugnumber, "github-issue-link")] attribute on them.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📝 For this issue, they'll have this form:

[WorkItem(18240, "https://github.com/dotnet/roslyn/issues/18240")]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this feels strange. Command should not be public here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i don't think command should be public here either.

@d0pare
Copy link
Copy Markdown
Author

d0pare commented Apr 5, 2017

Fixed all issues from review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

sure

@333fred
Copy link
Copy Markdown
Member

333fred commented Apr 5, 2017

Currently investigating vsi failures. Don't read anything into vsi failures for now.

@d0pare
Copy link
Copy Markdown
Author

d0pare commented Apr 7, 2017

Rebased onto roslyn/master

@sharwell
Copy link
Copy Markdown
Contributor

@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?

Copy link
Copy Markdown
Contributor

@sharwell sharwell left a comment

Choose a reason for hiding this comment

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

Two items to verify before merge:

  1. Retest against current master branch (retest is requested, but may require rebase)
  2. Add tests for protected private and update implementation if necessary

@d0pare
Copy link
Copy Markdown
Author

d0pare commented Apr 24, 2018

@sharwell Please take over. Currently I don't have enough time to make updates.

@sharwell sharwell added this to the 15.8 milestone May 25, 2018
@d0pare d0pare requested a review from a team as a code owner May 25, 2018 19:24
@jinujoseph
Copy link
Copy Markdown
Contributor

approved to merge for 15.8.preview3

@jinujoseph
Copy link
Copy Markdown
Contributor

test windows_release_vs-integration_prtest

@sharwell sharwell merged commit 00047b9 into dotnet:master Jun 4, 2018
@sharwell
Copy link
Copy Markdown
Contributor

sharwell commented Jun 4, 2018

@dopare Thank you! 😄

@d0pare
Copy link
Copy Markdown
Author

d0pare commented Jun 4, 2018

Holy moly, finally 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Approved to merge Area-IDE cla-already-signed Community The pull request was submitted by a contributor who is not a Microsoft employee.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Generate class ..." causes inconsistent accessibility

7 participants