From 3592f530302f8b474aa0f3dc2246c4f34f4283a2 Mon Sep 17 00:00:00 2001 From: CyrusNajmabadi Date: Sun, 18 Dec 2016 20:46:36 -0800 Subject: [PATCH] Ensure the syntax tree has the right options. --- .../CSharpInlineDeclarationDiagnosticAnalyzer.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Features/CSharp/Portable/InlineDeclaration/CSharpInlineDeclarationDiagnosticAnalyzer.cs b/src/Features/CSharp/Portable/InlineDeclaration/CSharpInlineDeclarationDiagnosticAnalyzer.cs index 8042c1b6320a1..d2f8c544a3d58 100644 --- a/src/Features/CSharp/Portable/InlineDeclaration/CSharpInlineDeclarationDiagnosticAnalyzer.cs +++ b/src/Features/CSharp/Portable/InlineDeclaration/CSharpInlineDeclarationDiagnosticAnalyzer.cs @@ -266,16 +266,20 @@ where outSymbol.Equals(symbol) currentLocalDeclarator, currentLocalDeclarator.WithInitializer(null)); + var rootWithoutInitializerTree = root.SyntaxTree.WithRootAndOptions( + rootWithoutInitializer, root.SyntaxTree.Options); + // Fork the compilation so we can do this analysis. var newCompilation = semanticModel.Compilation.ReplaceSyntaxTree( - root.SyntaxTree, rootWithoutInitializer.SyntaxTree); - var newSemanticModel = newCompilation.GetSemanticModel(rootWithoutInitializer.SyntaxTree); + root.SyntaxTree, rootWithoutInitializerTree); + var newSemanticModel = newCompilation.GetSemanticModel(rootWithoutInitializerTree); // NOTE: there is no current compiler API to determine if a variable is definitely // assigned or not. So, for now, we just get diagnostics for this block and see if // we get any definite assigment errors where we have a reference to the symbol. If // so, then we don't offer the fix. + rootWithoutInitializer = (CompilationUnitSyntax)rootWithoutInitializerTree.GetRoot(cancellationToken); var currentBlock = rootWithoutInitializer.GetCurrentNode(enclosingBlock); var diagnostics = newSemanticModel.GetDiagnostics(currentBlock.Span, cancellationToken);