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 requires two passes in the presence of directives inside lambda block bodies, inside argument lists #57465

Closed
davidwengier opened this issue Oct 29, 2021 · 3 comments · Fixed by #59654
Assignees
Labels
Area-IDE Bug IDE-Formatter Code formatter and/or smart indent Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented
Milestone

Comments

@davidwengier
Copy link
Contributor

Given the following code:

namespace N
{
    public class C
    {
        protected void Render()
        {
            if (true)
            {
                    M(() =>
                        {
#nullable enable
                               if (true)
                                    {
                                    }
                                }
                        );
                }
        }
    }
}

Formatting the document once results in:

namespace N
{
    public class C
    {
        protected void Render()
        {
            if (true)
            {
                M(() =>
                    {
#nullable enable
                            if (true)
                        {
                        }
                    }
                    );
            }
        }
    }
}

Note the position of the if (true). It has been moved by the formatter, but not by enough.

Foratting the document again results in:

namespace N
{
    public class C
    {
        protected void Render()
        {
            if (true)
            {
                M(() =>
                    {
#nullable enable
                        if (true)
                        {
                        }
                    }
                    );
            }
        }
    }
}

This is now properly formatted, and subsequent formatting does nothing, as you would expect.

Removing the #nullable enable from the file fixes the issue, and the formatter does the right thing on the first pass. Alternatively, changing the code so the lambda is assigned to a discard rather than passing it as an argument, also fixes the issue, even if the #nullable enable is left in place.

This bug is the cause of dotnet/razor#5676 in Razor, which generates code in a similar form to the example here.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Oct 29, 2021
@jinujoseph jinujoseph added Bug help wanted The issue is "up for grabs" - add a comment if you are interested in working on it IDE-Formatter Code formatter and/or smart indent and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Nov 4, 2021
@jinujoseph jinujoseph added this to the Backlog milestone Nov 4, 2021
@jinujoseph jinujoseph modified the milestones: Backlog, 17.1 Nov 4, 2021
@jinujoseph
Copy link
Contributor

Triage notes : Important for razor scenarios

@davidwengier
Copy link
Contributor Author

Another repro in Razor: dotnet/razor#5693

@sharwell sharwell added Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented and removed help wanted The issue is "up for grabs" - add a comment if you are interested in working on it labels Feb 23, 2022
@sharwell sharwell modified the milestones: 17.1, Next Feb 23, 2022
@RikkiGibson RikkiGibson modified the milestones: Next, 17.2.P2 Mar 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Bug IDE-Formatter Code formatter and/or smart indent Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants