dotnet/roslyn

NormalizeWhitespace incorrectly adds space after comma between omitted nodes

Open

#34,565 opened on Mar 28, 2019

View on GitHub
 (2 comments) (0 reactions) (0 assignees)C# (4,257 forks)batch import
Area-CompilersFeature Requesthelp wanted

Repository metrics

Stars
 (20,414 stars)
PR merge metrics
 (Avg merge 6d 17h) (256 merged PRs in 30d)

Description

Version Used: 3.0.0-beta4-final

Steps to Reproduce:

Run the following program:

using System;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;

class Program
{
    static void Main()
    {
        var type = ArrayType(PredefinedType(Token(SyntaxKind.IntKeyword)))
            .WithRankSpecifiers(SingletonList(ArrayRankSpecifier(
                SeparatedList<ExpressionSyntax>(
                    new[] { OmittedArraySizeExpression(), OmittedArraySizeExpression()}))));

        Console.WriteLine(type);
        Console.WriteLine(type.NormalizeWhitespace());

        var expression = TypeOfExpression(GenericName(Identifier("Dictionary"))
                .WithTypeArgumentList(TypeArgumentList(SeparatedList<TypeSyntax>(
                    new[] { OmittedTypeArgument(), OmittedTypeArgument()}))));

        Console.WriteLine(expression);
        Console.WriteLine(expression.NormalizeWhitespace());
    }
}

Expected Behavior:

NormalizeWhitespace does not add any whitespace here, so the program prints:

int[,]
int[,]
typeof(Dictionary<,>)
typeof(Dictionary<,>)

Actual Behavior:

int[,]
int[, ]
typeof(Dictionary<,>)
typeof(Dictionary<, >)

Contributor guide