Skip to content

Fixed collection and object initializer usage analysis not working in top-level code#61584

Merged
CyrusNajmabadi merged 6 commits intodotnet:mainfrom
DoctorKrolic:initializers-in-top-level-code
Jun 3, 2022
Merged

Fixed collection and object initializer usage analysis not working in top-level code#61584
CyrusNajmabadi merged 6 commits intodotnet:mainfrom
DoctorKrolic:initializers-in-top-level-code

Conversation

@DoctorKrolic
Copy link
Copy Markdown
Contributor

Fixes: #61066

Need help with tests here. Tried to add this test for object initializers:

        [WorkItem(61066, "https://github.com/dotnet/roslyn/issues/61066")]
        [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUseObjectInitializer)]
        public async Task TestInTopLevelStatements()
        {
            await TestInRegularAndScript1Async(
@"MyClass cl = [|new|]();
cl.MyProperty = 5;

class MyClass
{
    public int MyProperty { get; set; }
}",
@"MyClass cl = new()
{
    MyProperty = 5
}

class MyClass
{
    public int MyProperty { get; set; }
}");
        }

... and got CS8805 compiler error for some reason:
devenv_a3hS9BUnso

@DoctorKrolic DoctorKrolic requested a review from a team as a code owner May 29, 2022 11:47
@ghost ghost added Community The pull request was submitted by a contributor who is not a Microsoft employee. Area-IDE and removed Community The pull request was submitted by a contributor who is not a Microsoft employee. labels May 29, 2022
@CyrusNajmabadi
Copy link
Copy Markdown
Contributor

You need to set the output type of the test project to be a consoleapp, not a dll.

@DoctorKrolic
Copy link
Copy Markdown
Contributor Author

@CyrusNajmabadi Thanks, tests are now done. PR is ready for review

@DoctorKrolic
Copy link
Copy Markdown
Contributor Author

Can someone review this PR? Thanks in advance

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor

Done with pass.

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor

Done with pass. Only a couple of things to tweak :)

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor

Awesome, thanks!

@CyrusNajmabadi CyrusNajmabadi enabled auto-merge June 2, 2022 21:41
@DoctorKrolic
Copy link
Copy Markdown
Contributor Author

@CyrusNajmabadi Approve?)

@CyrusNajmabadi CyrusNajmabadi merged commit 318c113 into dotnet:main Jun 3, 2022
@ghost ghost added this to the Next milestone Jun 3, 2022
@CyrusNajmabadi
Copy link
Copy Markdown
Contributor

Yup yup. Thanks :-)

@DoctorKrolic DoctorKrolic deleted the initializers-in-top-level-code branch June 3, 2022 14:17
@Neme12
Copy link
Copy Markdown
Contributor

Neme12 commented Jun 3, 2022

It's such a shame that global statements have a wrapper node around each individual statement rather than having something like GlobalStatementsSyntax which would then have all the individual statements inside it. This way, it completely breaks the expectation that statements that are next to each other are actually next to each other in the syntax tree and a lot of features are currently broken and have to be specialized to make them work with top level statements 😞

@DoctorKrolic
Copy link
Copy Markdown
Contributor Author

Fully argree. But I guess it's our life now( Changing this behaviour into something better is too massive breaking change to be made.

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor

We have no cases of an empty nice that is only a wrapper around a SyntaxList. That itself would be an abnormality in the roslyn syntax model.

This upholds the invariant that all nodes have at least one node or token as a direct child.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IDE0017 is not proposed in top-level code

4 participants