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

Fix symbol info in identifier name in object initializer #74582

Merged

Conversation

Rekkonnect
Copy link
Contributor

Closes #74348

We now bind simple identifier name expressions as BoundObjectInitializerMember when inside an object initializer. Additionally, we also handle BoundObjectInitializerMember instances in the nullable walker and consider them as non null.

This approach follows the suggestion by @CyrusNajmabadi to handle this fix in the binder instead of the parser to avoid breaking too many parsing tests in the process.

@Rekkonnect Rekkonnect requested a review from a team as a code owner July 28, 2024 17:25
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Jul 28, 2024
@Rekkonnect Rekkonnect changed the title Fix symbol info in identifier name initializer Fix symbol info in identifier name in object initializer Jul 28, 2024
@dotnet-policy-service dotnet-policy-service bot added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label Jul 28, 2024
Copy link
Member

@333fred 333fred left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The general approach looks fine to me, but I have a few comments. I don't like the new NoneOperation in the tree here; it doesn't seem like it should be there.

bool isRef = refKind == RefKind.Ref;
var rhsKind = isRef ? GetRequiredRHSValueKindForRefAssignment(boundLeft) : BindValueKind.RValue;
// We fall back on simply binding the name as an expression for proper recovery
// and also report a diagnostic about this being an invalid value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might want to explain why this is beneficial.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an explanation, lmk if it's okay

Rekkonnect and others added 2 commits July 30, 2024 19:46
Co-authored-by: Cyrus Najmabadi <cyrus.najmabadi@gmail.com>
333fred
333fred previously approved these changes Sep 5, 2024
@333fred
Copy link
Member

333fred commented Sep 5, 2024

@dotnet/roslyn-compiler for a second review.

@333fred
Copy link
Member

333fred commented Sep 10, 2024

@dotnet/roslyn-compiler for a second review

@AlekseyTs
Copy link
Contributor

@Rekkonnect Could you resolve merge conflicts?

@AlekseyTs
Copy link
Contributor

Done with review pass (commit 9)

@@ -5267,6 +5267,380 @@ void F(int x = 2, = 3) { }
Assert.Same(symbol1.ContainingSymbol, symbol2.ContainingSymbol);
}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/74348")]
public void ObjectInitializerIncompletePropertyValueDeclaration01()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public

Consider adding similar tests for VB

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR only improves handling incorrect object initializers in C#, leaving VB unaffected. Do we want to add tests showing the current state of similar cases in VB?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to add tests showing the current state of similar cases in VB?

I think we do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the tests, lmk

@AlekseyTs
Copy link
Contributor

Done with review pass (commit 15)

@AlekseyTs
Copy link
Contributor

Done with review pass (commit 17)

Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (commit 18)

@AlekseyTs
Copy link
Contributor

@333fred For the second review

@333fred 333fred merged commit d9e3f4d into dotnet:main Oct 3, 2024
24 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Oct 3, 2024
@Rekkonnect Rekkonnect deleted the fix/74348-incomplete-setter-obj-initializer branch October 3, 2024 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Community The pull request was submitted by a contributor who is not a Microsoft employee. untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Gracefully handle incomplete property setter in object initializer
4 participants