Skip to content

Switch expressions have extra line breaks #1282

@charliefoxtwo

Description

@charliefoxtwo

There appears to be an extra line break in nested switch expressions, as well as for all default branches

Input:

public class ClassName {
    public bool Foo(object entry)
    {
        return entry switch
        {
            string s => s.Length switch
            {
                1 => true,
                2 => false,
                _ => throw new ArgumentOutOfRangeException("this specific string length is not supported"),
            },
            int i => i,
            _ => throw new ArgumentOutOfRangeException($"entry type {entry.GetType()} not supported"),
        };
    }
}

Output:

public class ClassName
{
    public bool Foo(object entry)
    {
        return entry switch
        {
            string s
                => s.Length switch
                {
                    1 => true,
                    2 => false,
                    _
                        => throw new ArgumentOutOfRangeException(
                            "this specific string length is not supported"
                        ),
                },
            int i => i,
            _
                => throw new ArgumentOutOfRangeException(
                    $"entry type {entry.GetType()} not supported"
                ),
        };
    }
}

Expected behavior:

public class ClassName {
    public bool Foo(object entry)
    {
        return entry switch
        {
            string s => s.Length switch
            {
                1 => true,
                2 => false,
                _ => throw new ArgumentOutOfRangeException(
                    "this specific string length is not supported"
                ),
            },
            int i => i,
            _ => throw new ArgumentOutOfRangeException(
                $"entry type {entry.GetType()} not supported"
            ),
        };
    }
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions