Skip to content
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

CSharpRemoveUnusedVariableCodeFixProvider does not work with top-level statements #44273

Closed
AlekseyTs opened this issue May 14, 2020 · 6 comments
Labels
Area-IDE Bug Feature - Simple Programs Top-level statements Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented

Comments

@AlekseyTs
Copy link
Contributor

AlekseyTs commented May 14, 2020

Start with top-level statement:

int abc = 123;

Use "Remove unused variable fix".
Observed:

System.ArgumentNullException : Value cannot be null.
Parameter name: statement
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitGlobalStatement(GlobalStatementSyntax node)
   at Microsoft.CodeAnalysis.CSharp.Syntax.GlobalStatementSyntax.Accept[TResult](CSharpSyntaxVisitor`1 visitor)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.Visit(SyntaxNode node)
   at Microsoft.CodeAnalysis.CSharp.Syntax.SyntaxNodeRemover.SyntaxRemover.Visit(SyntaxNode node)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitListElement[TNode](TNode node)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitList[TNode](SyntaxList`1 list)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitCompilationUnit(CompilationUnitSyntax node)
   at Microsoft.CodeAnalysis.CSharp.Syntax.CompilationUnitSyntax.Accept[TResult](CSharpSyntaxVisitor`1 visitor)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.Visit(SyntaxNode node)
   at Microsoft.CodeAnalysis.CSharp.Syntax.SyntaxNodeRemover.SyntaxRemover.Visit(SyntaxNode node)
   at Microsoft.CodeAnalysis.CSharp.Syntax.SyntaxNodeRemover.RemoveNodes[TRoot](TRoot root,IEnumerable`1 nodes,SyntaxRemoveOptions options)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxNode.RemoveNodesCore(IEnumerable`1 nodes,SyntaxRemoveOptions options)
   at Microsoft.CodeAnalysis.SyntaxNodeExtensions.RemoveNode[TRoot](TRoot root,SyntaxNode node,SyntaxRemoveOptions options)
   at Microsoft.CodeAnalysis.Editing.SyntaxGenerator.RemoveNode(SyntaxNode root,SyntaxNode node,SyntaxRemoveOptions options)
   at Microsoft.CodeAnalysis.CSharp.CodeGeneration.CSharpSyntaxGenerator.RemoveNodeInternal(SyntaxNode root,SyntaxNode declaration,SyntaxRemoveOptions options)
   at Microsoft.CodeAnalysis.CSharp.CodeGeneration.CSharpSyntaxGenerator.<>c__DisplayClass198_0.<RemoveNode>b__0(SyntaxNode r)
   at Microsoft.CodeAnalysis.Editing.SyntaxGenerator.PreserveTrivia[TNode](TNode node,Func`2 nodeChanger)
   at Microsoft.CodeAnalysis.CSharp.CodeGeneration.CSharpSyntaxGenerator.Isolate(SyntaxNode declaration,Func`2 editor)
   at Microsoft.CodeAnalysis.CSharp.CodeGeneration.CSharpSyntaxGenerator.RemoveNode(SyntaxNode root,SyntaxNode node,SyntaxRemoveOptions options)
   at Microsoft.CodeAnalysis.Editing.SyntaxEditor.RemoveChange.Apply(SyntaxNode root,SyntaxGenerator generator)
   at Microsoft.CodeAnalysis.Editing.SyntaxEditor.GetChangedRoot()
   at async Microsoft.CodeAnalysis.CodeFixes.SyntaxEditorBasedCodeFixProvider.FixAllWithEditorAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeActions.CodeAction.GetChangedSolutionAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeActions.CodeAction.ComputeOperationsAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeActions.CodeAction.GetPreviewOperationsAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedAction.GetPreviewResultAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedActionWithNestedFlavors.<>c__DisplayClass11_0.<GetPreviewAsync>b__0(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.Extensions.IExtensionManagerExtensions.PerformFunctionAsync[T](<Unknown Parameters>)
   at Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)

Relates to #43563 (test plan for "top-level statements")

@AlekseyTs
Copy link
Contributor Author

CC @sharwell

@CyrusNajmabadi
Copy link
Member

I'm a little surprised by these issues. We should have had some amount of testing of these scenarios for the existing top-level-statements features (i.e. interactive). Is there something very different about the simple-program top-level statements, and interactive top-level statements?

@AlekseyTs
Copy link
Contributor Author

No, difference for the syntax tree shape

@AlekseyTs
Copy link
Contributor Author

Actually, that is not accurate, there is no locals and local functions in interactive, they are fields and methods. So, there is a difference in syntax shape

@sharwell sharwell changed the title CSharpRemoveUnusedVariableCodeFixProvider encountered an error and has been disabled CSharpRemoveUnusedVariableCodeFixProvider does not work with top-level statements May 15, 2020
@jcouv jcouv self-assigned this May 20, 2020
@jcouv
Copy link
Member

jcouv commented May 20, 2020

I'll take a look to block or fix this today

@jinujoseph jinujoseph added the Bug label May 20, 2020
@jinujoseph jinujoseph added this to the 16.7 milestone May 20, 2020
@AlekseyTs AlekseyTs modified the milestones: 16.7, 16.7.P2 May 20, 2020
@jinujoseph jinujoseph modified the milestones: 16.7.P2, 16.7 Jun 9, 2020
@jcouv jcouv removed their assignment Jun 24, 2020
@jinujoseph jinujoseph modified the milestones: 16.7, Backlog Jul 26, 2020
@sharwell sharwell removed this from the Backlog milestone Sep 10, 2020
@sharwell
Copy link
Member

This was fixed by #44455. @jcouv Can you update the milestone for when this actually shipped?

@sharwell sharwell added the Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented label Sep 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Bug Feature - Simple Programs Top-level statements Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented
Projects
None yet
Development

No branches or pull requests

5 participants