Skip to content

Simplify Inline Temporary refactoring for tuples #11028

@jcouv

Description

@jcouv

The generated code below is un-necessarily complicated. Dustin suggested to track an issue for the simplifier.
Note: it may be better to wait for the tuple conversion work which Vlad will do next week, as it might make the problem easier.

  public async Task TuplesWithDifferentNames()
        {
            var code = @"
class C
{
    public void M()
    {
        (int a, string b) [||]x = (c: 1, d: ""hello"");
        x.a.ToString();
    }
}";

            var expected = @"
class C
{
    public void M()
    {
        (((int a, string b))((c: (int)1, d: (string)""hello""))).a.ToString();
    }
}";

            await TestAsync(code, expected, index: 0, compareTokens: false, parseOptions: TestOptions.Regular.WithTuplesFeature());
        }

File is InlineTemporaryTests.cs.

There are some other refactorings which may be improved by this simplification. They print code like default((string c, int d)). See TestTupleOptionalWithNames in AddConstructorParametersTests.cs, and TupleWithNames_Equals and TupleWithNames_HashCode in GenerateEqualsAndGetHashCodeTests.cs

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions