Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatter doesn't increase ident in multiline list patterns correctly #73251

Open
DoctorKrolic opened this issue Apr 27, 2024 · 1 comment
Open
Labels
Area-IDE Bug help wanted The issue is "up for grabs" - add a comment if you are interested in working on it
Projects
Milestone

Comments

@DoctorKrolic
Copy link
Contributor

Found while working on a compiler PR (link)

Version Used:
VS 17.10.0 Preview 5.0

Steps to Reproduce:
Run formatter on this code:

MyClass[] arr = [new()];

if (arr is
    [
    {
        Prop: 1,
        AnotherProp: 2
    }
    ])
{

}

class MyClass
{
    public int Prop { get; set; }

    public int AnotherProp { get; set; }
}

Expected Behavior:

MyClass[] arr = [new()];

if (arr is
    [
        {
            Prop: 1,
            AnotherProp: 2
        }
    ])
{

}

class MyClass
{
    public int Prop { get; set; }

    public int AnotherProp { get; set; }
}

Actual Behavior:
Quite the opposite - when I run formatting on correct code, it dedents it back:
formatterBug

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 27, 2024
@CyrusNajmabadi CyrusNajmabadi added Bug help wanted The issue is "up for grabs" - add a comment if you are interested in working on it and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 27, 2024
@CyrusNajmabadi CyrusNajmabadi added this to InQueue in Small Fixes via automation Apr 27, 2024
@CyrusNajmabadi CyrusNajmabadi added this to the Backlog milestone Apr 27, 2024
@RikkiGibson
Copy link
Contributor

I suspect the same issue may be occurring here, even though there is no collection-expr involved.

Before:

if (sym switch
    {
        MethodSymbol method => (Symbol)method.PartialImplementationPart,
        SourcePropertySymbol property => property.PartialImplementationPart,
        _ => throw ExceptionUtilities.UnexpectedValue(sym)
    }
    is { } implementation)
{

After:

if (sym switch
{
    MethodSymbol method => (Symbol)method.PartialImplementationPart,
    SourcePropertySymbol property => property.PartialImplementationPart,
    _ => throw ExceptionUtilities.UnexpectedValue(sym)
}
    is { } implementation)
{

Expected: no formatting warning is reported for the "Before" case.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Bug help wanted The issue is "up for grabs" - add a comment if you are interested in working on it
Projects
Small Fixes
  
InQueue
Development

No branches or pull requests

3 participants