title: SemanticModel GetSymbolInfo().Symbol is Null in Constructed Code but not Parsed Code
body: <p>Given the following code</p>
  
  <pre><code>var forText = "int i;for(i=0;i&lt;3;i++){}";
  </code></pre>
  
  <p>I wish to grab a reference to the <code>i</code> in <code>i=0</code>, and then request its symbol info to see where it was declared, if anywhere! To do this using the string above, you would do the following</p>
  
  <pre><code>var forText = "int i;for(i=0;i&lt;3;i++){}";
  var mscorlib = MetadataReference.CreateFromFile(typeof(object).Assembly.Location);
  var options = CSharpParseOptions.Default.WithKind(SourceCodeKind.Script);
  
  var goodTree = CSharpSyntaxTree.ParseText(forText, options);
  var goodCompilation = CSharpCompilation.CreateScriptCompilation("GoodCompilation", syntaxTree: goodTree, references: new[] { mscorlib });
  var goodModel = goodCompilation.GetSemanticModel(goodTree);
  
  var goodLeft = goodTree.GetRoot().DescendantNodes().OfType&lt;AssignmentExpressionSyntax&gt;().First().Left;
  
  var goodSymbol = goodModel.GetSymbolInfo(goodLeft).Symbol;
  </code></pre>
  
  <p>This works fine as expected, and <code>goodSymbol</code> is successfully assigned a value. However, in my program what I need to do is perform semantic analysis against an existing syntax tree. For some reason however, if the tree above is manually created via <code>SyntaxFactory</code> nodes, <code>GetSymbolInfo().Symbol</code> returns <code>null</code>!</p>
  
  <pre><code>//using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
  
  var manualTree = CompilationUnit()
      .WithMembers(
          List(new MemberDeclarationSyntax[] {
              GlobalStatement(
                  LocalDeclarationStatement(
                      VariableDeclaration(
                          PredefinedType(Token(SyntaxKind.IntKeyword)),
                          SingletonSeparatedList(
                              VariableDeclarator("i")
                          )
                       )
                  ).NormalizeWhitespace()
              ),
              GlobalStatement(
                  ForStatement(
                      null,
                      SingletonSeparatedList&lt;ExpressionSyntax&gt;(
                          AssignmentExpression(SyntaxKind.SimpleAssignmentExpression,
                              IdentifierName("i"),
                              LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(0))
                          )
                      ),
                      BinaryExpression(
                          SyntaxKind.LessThanExpression,
                          IdentifierName("i"),
                          LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(3))
                      ),
                      SingletonSeparatedList&lt;ExpressionSyntax&gt;(
                          PostfixUnaryExpression(SyntaxKind.PostIncrementExpression,
                              IdentifierName("i")
                          )
                      ),
                      Block()
                  )
              )}
          ));
  
  var badTree = CSharpSyntaxTree.Create(manualTree, CSharpParseOptions.Default.WithKind(SourceCodeKind.Script));
  
  var badCompilation = CSharpCompilation.CreateScriptCompilation("BadCompilation", syntaxTree: badTree, references: new[] { mscorlib });
  var badModel = badCompilation.GetSemanticModel(badTree);
  
  var badLeft = badTree.GetRoot().DescendantNodes().OfType&lt;AssignmentExpressionSyntax&gt;().First().Left;
  
  var badSymbol = badModel.GetSymbolInfo(badLeft).Symbol;
  </code></pre>
  
  <p>The nodes and tokens in both trees appear to be exactly the same; there do not appear to be any nodes in the <code>goodTree</code> that are reused in multiple places (each <code>SyntaxNode</code> has a unique object reference) - there is simply something fundamentally different about the parsed tree to the constructed tree, but I have no idea what! Both trees have the exact same string representation, so there must be some kind of metadata on either the <code>SyntaxTree</code> or some of the <code>SyntaxNode</code> objects that makes this work in <em>good</em> but not <em>bad</em></p>