Syntax.ParseCompilationUnit(" ").GetLeadingTrivia().Count should be greater than zero
-
2012年2月21日 6:18
I expected Syntax.ParseCompilationUnit(" ").GetLeadingTrivia().Count to be greater than zero but I actually got zero. The leading trivia is on the EOF token but CompilationUnitSyntax is not returning it. CompilationUnitSyntax's traversal to find the first token is failing when the first token is the EOF token.
Thanks,
Chris
全部回复
-
2012年2月21日 21:22所有者:
This is certainly a bug. For the above CompilationUnitSyntax, .HasLeadingTrivia returns true and .GetLeadingTrivia().Count returns 0 [although the trivia can be accessed using .DescendentTrivia()]. .HasLeadingTrivia and .GetLeadingTrivia() mustn't disagree.
I tried the (below) repro against our latest internal build and can confirm that the issue does not repro there. So this should be fixed in the next public release...
var node = Syntax.ParseCompilationUnit(" "); Console.WriteLine("HasLeadingTrivia: " + node.HasLeadingTrivia); Console.WriteLine("GetLeadingTrivia().Count: " + node.GetLeadingTrivia().Count); foreach (var tr in node.GetLeadingTrivia()) Console.WriteLine(" Leading: '" + tr.GetText() + "'"); Console.WriteLine("DescendentTrivia().Count(): " + node.DescendentTrivia().Count()); foreach (var tr in node.DescendentTrivia()) Console.WriteLine(" Descendent Leading: '" + tr.GetText() + "'");
Shyam Namboodiripad | Software Development Engineer in Test | Roslyn Compilers Team

