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

UseExplicitType: var in deconstruction is rewritten with unexpected newlines #24060

Closed
jcouv opened this issue Jan 5, 2018 · 1 comment
Closed
Assignees
Labels

Comments

@jcouv
Copy link
Member

jcouv commented Jan 5, 2018

A number of undesirable newlines get added to the generated code during formatting.

As far as I can tell the root cause of the newlines getting added is AbstractTriviaFormatter.GetLineColumnOfWhitespace which returns a value with lines=1. This causes AbstractTriviaFormatter.AddWhitespaceTextChange to add a newline.

        [WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsUseExplicitType)]
        [WorkItem(23752, "https://github.com/dotnet/roslyn/issues/23752")]
        public async Task OnNestedDeconstructionVarWithTrivia()
        {
            await TestInRegularAndScriptAsync(
@"using System;
class Program
{
    void M()
    {
        /*before*/[|var|]/*after*/ (/*x1*/x/*x2*/, /*yz1*/(/*y1*/y/*y2*/, /*z1*/z/*z2*/)/*yz2*/) /*end*/ = new Program();
    }
    void Deconstruct(out int i, out Program s) { i = 1; s = null; }
}", @"using System;
class Program
{
    void M()
    {
        /*before*//*after*/ (
/*x1*/int x/*x2*/,
/*yz1*/(
/*y1*/int y/*y2*/,
/*z1*/Program z/*z2*/)/*yz2*/) /*end*/ = new Program();
    }
    void Deconstruct(out int i, out Program s) { i = 1; s = null; }
}", options: ExplicitTypeEverywhere());
        }
@jcouv
Copy link
Member Author

jcouv commented Jan 5, 2018

Found a solution after all.

@jcouv jcouv closed this as completed Jan 5, 2018
@jcouv jcouv self-assigned this Jan 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant