Skip to content

Commit

Permalink
Make sure to use the original semantic model when checking for using …
Browse files Browse the repository at this point in the history
…alias directives
  • Loading branch information
sharwell committed Dec 5, 2017
1 parent fd9bafb commit 4d9f709
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1013,9 +1013,17 @@ private static bool TryReplaceWithAlias(this ExpressionSyntax node, SemanticMode
// might be a speculative node (not fully rooted in a tree), we use the position of the evaluation to find
// the equivalent node in the original tree, and from there determine if the tree has any using alias
// directives.
if (semanticModel.SyntaxTree.TryGetRoot(out var root))
var originalModel = semanticModel;
var originalPosition = node.SpanStart;
while (originalModel.IsSpeculativeSemanticModel)
{
var token = root.FindTokenOnLeftOfPosition(node.SpanStart);
originalPosition = originalModel.OriginalPositionForSpeculation;
originalModel = originalModel.ParentModel;
}

if (originalModel.SyntaxTree.TryGetRoot(out var root))
{
var token = root.FindTokenOnLeftOfPosition(originalPosition);
var tokenParent = token.Parent;
var aliasContainer = tokenParent?.FirstAncestorOrSelf<SyntaxNode>(
syntax =>
Expand Down

0 comments on commit 4d9f709

Please sign in to comment.