提交 eb661048 编写于 作者: B Balaji Soundrarajan

Dont Assume Certain Node Are Always Parented

Fix 1118 : Dont assume that some of the nodes are always parented.
Always check if the parent is not null before accessing the parent.
上级 54f1dc52
......@@ -98,8 +98,7 @@ public static bool IsLambdaBodyBlock(this SyntaxNode node)
return false;
}
return node.Parent.Kind() == SyntaxKind.SimpleLambdaExpression ||
node.Parent.Kind() == SyntaxKind.ParenthesizedLambdaExpression;
return node.IsParentKind(SyntaxKind.SimpleLambdaExpression) || node.IsParentKind(SyntaxKind.ParenthesizedLambdaExpression);
}
public static bool IsAnonymousMethodBlock(this SyntaxNode node)
......@@ -109,7 +108,7 @@ public static bool IsAnonymousMethodBlock(this SyntaxNode node)
return false;
}
return node.Parent.Kind() == SyntaxKind.AnonymousMethodExpression;
return node.IsParentKind(SyntaxKind.AnonymousMethodExpression);
}
public static bool IsSemicolonInForStatement(this SyntaxToken token)
......@@ -502,7 +501,7 @@ public static bool IsBlockBody(this SyntaxNode node)
Contract.ThrowIfNull(node);
var blockNode = node as BlockSyntax;
if (blockNode == null)
if (blockNode == null || blockNode.Parent == null)
{
return false;
}
......
......@@ -6010,5 +6010,13 @@ static void Main(string[] args)
}";
AssertFormat(expected, code);
}
[WorkItem(1118, "https://github.com/dotnet/roslyn/issues/1118")]
[Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
public void DontAssumeCertainNodeAreAlwaysParented()
{
var block = SyntaxFactory.Block();
Formatter.Format(block, new AdhocWorkspace());
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册