Skip to content

Add code fix for CS0513#40448

Merged
mavasani merged 10 commits intodotnet:masterfrom
Evangelink:codefix-CS0513
Jul 6, 2020
Merged

Add code fix for CS0513#40448
mavasani merged 10 commits intodotnet:masterfrom
Evangelink:codefix-CS0513

Conversation

@Evangelink
Copy link
Member

Make enclosing class abstract when member does not have body.

Fix #31833

Make enclosing class abstract when member does not have body.
@Evangelink Evangelink requested a review from a team as a code owner December 17, 2019 15:17
{
var enclosingClass = declaration.FirstAncestorOrSelf<TClassDeclarationSyntax>();
editor.ReplaceNode(enclosingClass,
(currentClassDeclaration, generator) => generator.WithModifiers(currentClassDeclaration, DeclarationModifiers.Abstract));
Copy link
Contributor

Choose a reason for hiding this comment

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

won't this blow away other modifiers? don't you need to 'union' this with the existing mods?

Copy link
Member Author

Choose a reason for hiding this comment

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

That was my thought at first but this seem to keep the existing modifiers and just apply the new one (with some validity check).

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, the current behavior seems strange to me for a With method. Ideally it should overwrite, not merge. It is unlikely we would change the behavior though as it would be a breaking change.

Copy link
Member Author

Choose a reason for hiding this comment

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

@mavasani Well it can simply be overwrite as we need to keep the other modifiers or am I missing something?

Copy link
Member Author

Choose a reason for hiding this comment

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

@mavasani so what do you want me to do here?

@CyrusNajmabadi
Copy link
Contributor

hey @Evangelink Thanks for the PR!

@CyrusNajmabadi
Copy link
Contributor

Missing VB impl and tests currently. Can you add those?

@Evangelink
Copy link
Member Author

@CyrusNajmabadi I haven't added an impl for VB.NET because I couldn't find the equivalent error in Errors.vb looking for abstract or mustinherit. If you could point me to the error, I'll gladly provide the impl.

@Evangelink Evangelink requested review from CyrusNajmabadi and removed request for a team December 19, 2019 16:09
@CyrusNajmabadi
Copy link
Contributor

Just experiment in VB to see waht you get. For example, i tried this out:

image

And got htis error:

Severity	Code	Description	Project	File	Line	Suppression State
Error	BC31411	'C' must be declared 'MustInherit' because it contains methods declared 'MustOverride'

@jcouv
Copy link
Member

jcouv commented Jan 3, 2020

@vatsalyaagrawal I removed the Area-Compilers label as I don't see any compiler file change. Let me know if I missed something. Thanks

@jinujoseph jinujoseph added Area-IDE Community The pull request was submitted by a contributor who is not a Microsoft employee. Feature Request labels Jan 4, 2020
@jinujoseph jinujoseph added this to the 16.5.P2 milestone Jan 4, 2020
Copy link
Contributor

@mavasani mavasani left a comment

Choose a reason for hiding this comment

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

Overall LGTM. Some minor suggestions and an open question on whether the abstract modifier should be added to all declarations of a partial type.

@jinujoseph jinujoseph modified the milestones: 16.5.P2, 16.6 Feb 21, 2020
@jinujoseph jinujoseph modified the milestones: 16.6, 16.7 Apr 19, 2020
@mavasani
Copy link
Contributor

@Evangelink can you please resolve conflicts and fix CI?

@Evangelink
Copy link
Member Author

I have "fixed" the CI but I don't understand why so many cases do not work for vbnet (including the fixall), the implementation seems to match other codefix.

@Evangelink Evangelink requested a review from mavasani July 3, 2020 14:44
@Evangelink
Copy link
Member Author

See #42814

@Evangelink
Copy link
Member Author

@mavasani I don't understand what's going wrong with the tests/PR. I have copied the behavior/structure from the AbstractMakeMemberStaticCodeFixProvider (and sub-classes).


namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.MakeClassAbstract
{
public class MakeClassAbstractTests : AbstractCSharpDiagnosticProviderBasedUserDiagnosticTest
Copy link
Contributor

Choose a reason for hiding this comment

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

@Evangelink Can we instead just convert these tests to use the new test framework? Will that be too much work? That will avoid you having to add a public ctor for this code fixer and then suppressing RS0033.

Copy link
Contributor

Choose a reason for hiding this comment

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

If https://github.com/dotnet/roslyn/pull/40448/files#r450282581 addresses the CI, it is fine to skip changing the tests for this PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have tried (if I got it right that the syntax is the same as for roslyn-analyzers) but I end-up with nuget errors: NuGet.Protocol.Core.Types.FatalProtocolException : Unable to load the service index for source https://api.nuget.org/v3/index.json.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is fine to not do this as part of this PR. You may want to file a follow-up issue with your questions. Also suggest looking at the existing tests which are already moved to new framework, for example: https://github.com/dotnet/roslyn/blob/master/src/Analyzers/CSharp/Tests/RemoveUnnecessaryImports/RemoveUnnecessaryImportsTests.cs

@mavasani mavasani merged commit 195ddaf into dotnet:master Jul 6, 2020
@ghost ghost modified the milestones: 16.7, Next Jul 6, 2020
@mavasani mavasani modified the milestones: Next, 16.8, 16.8.P1 Jul 6, 2020
@Evangelink Evangelink deleted the codefix-CS0513 branch July 6, 2020 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-IDE Community The pull request was submitted by a contributor who is not a Microsoft employee. Feature Request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Code fix for CS0513 to make class abstract

6 participants