Skip to content

Event handler lambda formatting incorrectly indents the body #7704

@SolalPirelli

Description

@SolalPirelli

Repro:

In VS2015 with update 1, set the C# formatting preferences to insert spaces before and after binary operators.

Write the following class:

class C
{
    public static event Action E;
}

(static doesn't influence the bug, it's just more convenient for the next example)

Then write exactly the following code in a method:

C.E+=() => 
{
}

Format the file.

Expected result:

C.E += () =>
{
}

Actual result:

C.E += () =>
  {
  }

The indent of the body is wrong.

Experimenting a bit, it seems the body indent is (1 - <#spaces left of +=>) + (1 - <#spaces right of +=>) when it should be 0.

Adding things to the lambda body before formatting gets funky results, especially if comments are involved (some statements are indented, some aren't, the closing brace isn't always indented...).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions