Skip to content

Generate Constructor should not copy "protected" from abstract base class (#25238)#25866

Merged
heejaechang merged 7 commits intodotnet:masterfrom
angelina-dev:generate-public-constructor-for-concrete-class
Apr 3, 2018
Merged

Generate Constructor should not copy "protected" from abstract base class (#25238)#25866
heejaechang merged 7 commits intodotnet:masterfrom
angelina-dev:generate-public-constructor-for-concrete-class

Conversation

@angelina-dev
Copy link
Copy Markdown
Contributor

@angelina-dev angelina-dev commented Apr 1, 2018

fixes : #25238

There was no answer to my question in comments for the issue: "If a base class is not abstract, it looks like we should make the constructor of the derived class public. What do you think?". So the implementation did not affect this case and a constructor is still generated with the same access modifier as base constructor.

@angelina-dev angelina-dev requested a review from a team as a code owner April 1, 2018 03:00
@dnfclas
Copy link
Copy Markdown

dnfclas commented Apr 1, 2018

CLA assistant check
All CLA requirements met.


namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.GenerateDefaultConstructors
{
public class GenerateConstructorForAbstractClassTests : AbstractCSharpCodeActionTest
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.

Thanks for the PR :)

we don't need a new test class for these tests. It should just go in the primary test class htat already exists for this feature. You can put it in another partial-part if you want to (though i would not recommend that personally).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you for Code Review 👍
Done.

public async Task TestGenerateConstructorFromProtectedConstructor()
{
await TestInRegularAndScriptAsync(
@"abstract class C : [||]B
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.

you don't have to change up all these test. But i found them odd to read as you had to read out of order. isntead of seeing hte base type, then the dependent type, you see the dependent type and then have to find the base type.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I agree. The tests were written in the same way as in GenerateDefaultConstructorsTests.cs.

var classType = _state.ClassType;
var accessibility = baseConstructor.ContainingType.IsAbstractClass() ?
(classType.IsAbstractClass() ? baseConstructor.DeclaredAccessibility : Accessibility.Public)
: baseConstructor.DeclaredAccessibility;
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.

IDE style would be:

var accessibility = baseConstructor.ContainingType.IsAbstractClass()
    ? classType.IsAbstractClass() ? baseConstructor.DeclaredAccessibility : Accessibility.Public
    : baseConstructor.DeclaredAccessibility;

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.

or:

var accessibility = baseConstructor.ContainingType.IsAbstractClass()
    ? classType.IsAbstractClass()
        ? baseConstructor.DeclaredAccessibility
        : Accessibility.Public
    : baseConstructor.DeclaredAccessibility;

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.

interesting bit of logic... I would personally just prefer:

var accessibility  = baseConstructor.ContainingType.IsAbstractClass() && !classType.IsAbstractClass()
    ? Accessibility.Public
    : baseConstructor.DeclaredAccessibility;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done like in Neme12's suggestion

@heejaechang
Copy link
Copy Markdown
Contributor

@jinujoseph 15.7?

@jinujoseph jinujoseph added this to the 15.8 milestone Apr 3, 2018
@jinujoseph
Copy link
Copy Markdown
Contributor

@angelina-dev Thanks much for the PR.
@heejaechang , Lets take this in 15.8 , don't see a reason to rush for 15.7 (correct me if there is one)

@heejaechang
Copy link
Copy Markdown
Contributor

@jinujoseph for 15.8 do I need approval? or sign off is all I need?

@jinujoseph
Copy link
Copy Markdown
Contributor

no ask approvals needed
review sign off + test pass needed

@heejaechang
Copy link
Copy Markdown
Contributor

@dotnet/roslyn-infrastructure jenkins issue

D:\j\workspace\windows_relea---a23004dd\Binaries\Tools\dotnet\sdk\2.1.300-preview2-008324\NuGet.targets(114,5): error : Failed to retrieve information about 'Microsoft.VisualStudio.Text.UI.Wpf' from remote source

https://ci.dot.net/job/dotnet_roslyn/job/master/job/windows_release_unit32_prtest/12806/console

@heejaechang
Copy link
Copy Markdown
Contributor

again, Jenkins issue. myget is down.

@heejaechang
Copy link
Copy Markdown
Contributor

retest windows_release_unit32_prtest please

@heejaechang heejaechang merged commit d5216b5 into dotnet:master Apr 3, 2018
@angelina-dev angelina-dev deleted the generate-public-constructor-for-concrete-class branch April 3, 2018 20:09
@DustinCampbell
Copy link
Copy Markdown
Member

Awesome! I've been wanting this for awhile.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generate Constructor should not copy "protected" from abstract base class

7 participants