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

NullReferenceException in SyntaxRemover.VisitGlobalStatement with top-level statement #44385

Closed
cston opened this issue May 19, 2020 · 3 comments
Labels
Milestone

Comments

@cston
Copy link
Member

cston commented May 19, 2020

  1. Run devenv.exe with commit 9be1ef7.
  2. Create Console Application
  3. Replace Program.cs contents with:
int x = 1;

class Program
{
    static void Main(string[] args)
    {
    }
}
  1. Click on fix for int x = 1; statement, and choose "Remove unused variable"
NullReferenceException:
>	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitGlobalStatement(Microsoft.CodeAnalysis.CSharp.Syntax.GlobalStatementSyntax node) Line 1851	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Syntax.GlobalStatementSyntax.Accept<Microsoft.CodeAnalysis.SyntaxNode>(Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor<Microsoft.CodeAnalysis.SyntaxNode> visitor) Line 4881	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.Visit(Microsoft.CodeAnalysis.SyntaxNode node) Line 41	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Syntax.SyntaxNodeRemover.SyntaxRemover.Visit(Microsoft.CodeAnalysis.SyntaxNode node) Line 176	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitListElement<Microsoft.CodeAnalysis.CSharp.Syntax.MemberDeclarationSyntax>(Microsoft.CodeAnalysis.CSharp.Syntax.MemberDeclarationSyntax node) Line 167	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitList<Microsoft.CodeAnalysis.CSharp.Syntax.MemberDeclarationSyntax>(Microsoft.CodeAnalysis.SyntaxList<Microsoft.CodeAnalysis.CSharp.Syntax.MemberDeclarationSyntax> list) Line 144	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitCompilationUnit(Microsoft.CodeAnalysis.CSharp.Syntax.CompilationUnitSyntax node) Line 1980	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Syntax.CompilationUnitSyntax.Accept<Microsoft.CodeAnalysis.SyntaxNode>(Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor<Microsoft.CodeAnalysis.SyntaxNode> visitor) Line 7750	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.Visit(Microsoft.CodeAnalysis.SyntaxNode node) Line 41	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Syntax.SyntaxNodeRemover.SyntaxRemover.Visit(Microsoft.CodeAnalysis.SyntaxNode node) Line 176	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Syntax.SyntaxNodeRemover.RemoveNodes<Microsoft.CodeAnalysis.CSharp.CSharpSyntaxNode>(Microsoft.CodeAnalysis.CSharp.CSharpSyntaxNode root, System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.SyntaxNode> nodes, Microsoft.CodeAnalysis.SyntaxRemoveOptions options) Line 34	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.CSharpSyntaxNode.RemoveNodesCore(System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.SyntaxNode> nodes, Microsoft.CodeAnalysis.SyntaxRemoveOptions options) Line 525	C#
 	Microsoft.CodeAnalysis.dll!Microsoft.CodeAnalysis.SyntaxNodeExtensions.RemoveNode<Microsoft.CodeAnalysis.SyntaxNode>(Microsoft.CodeAnalysis.SyntaxNode root, Microsoft.CodeAnalysis.SyntaxNode node, Microsoft.CodeAnalysis.SyntaxRemoveOptions options) Line 269	C#
 	Microsoft.CodeAnalysis.Workspaces.dll!Microsoft.CodeAnalysis.Editing.SyntaxGenerator.RemoveNode(Microsoft.CodeAnalysis.SyntaxNode root, Microsoft.CodeAnalysis.SyntaxNode node, Microsoft.CodeAnalysis.SyntaxRemoveOptions options) Line 1199	C#
 	Microsoft.CodeAnalysis.CSharp.Workspaces.dll!Microsoft.CodeAnalysis.CSharp.CodeGeneration.CSharpSyntaxGenerator.RemoveNodeInternal(Microsoft.CodeAnalysis.SyntaxNode root, Microsoft.CodeAnalysis.SyntaxNode declaration, Microsoft.CodeAnalysis.SyntaxRemoveOptions options) Line 2945	C#
 	Microsoft.CodeAnalysis.CSharp.Workspaces.dll!Microsoft.CodeAnalysis.CSharp.CodeGeneration.CSharpSyntaxGenerator.RemoveNode.AnonymousMethod__0(Microsoft.CodeAnalysis.SyntaxNode r) Line 2886	C#
 	Microsoft.CodeAnalysis.Workspaces.dll!Microsoft.CodeAnalysis.Editing.SyntaxGenerator.PreserveTrivia<Microsoft.CodeAnalysis.SyntaxNode>(Microsoft.CodeAnalysis.SyntaxNode node, System.Func<Microsoft.CodeAnalysis.SyntaxNode, Microsoft.CodeAnalysis.SyntaxNode> nodeChanger) Line 1254	C#
 	Microsoft.CodeAnalysis.CSharp.Workspaces.dll!Microsoft.CodeAnalysis.CSharp.CodeGeneration.CSharpSyntaxGenerator.Isolate(Microsoft.CodeAnalysis.SyntaxNode declaration, System.Func<Microsoft.CodeAnalysis.SyntaxNode, Microsoft.CodeAnalysis.SyntaxNode> editor) Line 1959	C#
 	Microsoft.CodeAnalysis.CSharp.Workspaces.dll!Microsoft.CodeAnalysis.CSharp.CodeGeneration.CSharpSyntaxGenerator.RemoveNode(Microsoft.CodeAnalysis.SyntaxNode root, Microsoft.CodeAnalysis.SyntaxNode node, Microsoft.CodeAnalysis.SyntaxRemoveOptions options) Line 2886	C#
 	Microsoft.CodeAnalysis.Workspaces.dll!Microsoft.CodeAnalysis.Editing.SyntaxEditor.RemoveChange.Apply(Microsoft.CodeAnalysis.SyntaxNode root, Microsoft.CodeAnalysis.Editing.SyntaxGenerator generator) Line 294	C#
 	Microsoft.CodeAnalysis.Workspaces.dll!Microsoft.CodeAnalysis.Editing.SyntaxEditor.GetChangedRoot() Line 88	C#
 	Microsoft.CodeAnalysis.Workspaces.dll!Microsoft.CodeAnalysis.CodeFixes.SyntaxEditorBasedCodeFixProvider.FixAllWithEditorAsync(Microsoft.CodeAnalysis.Document document, System.Func<Microsoft.CodeAnalysis.Editing.SyntaxEditor, System.Threading.Tasks.Task> editAsync, System.Threading.CancellationToken cancellationToken) Line 47	C#
@cston
Copy link
Member Author

cston commented May 19, 2020

cc @AlekseyTs

@cston cston added this to the 16.7 milestone May 19, 2020
@AlekseyTs
Copy link
Contributor

@cston Is this a dupe of #44273?

@jcouv
Copy link
Member

jcouv commented May 20, 2020

Yes, this is a dupe of #44273. I'm working on a fix. Closing

@jcouv jcouv closed this as completed May 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants