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

Handle indexers in nested object initializers #48168

Merged
merged 4 commits into from
Oct 5, 2020

Conversation

333fred
Copy link
Member

@333fred 333fred commented Sep 29, 2020

When I removed the usage of Lazy<T> from IOperation, I mishandled setting whether a property initializer in a nested object initializer expression is a object initializer itself. This meant that during the build of the parent node, we'd correctly check the setter for the property to ensure that it was valid, but then when handling deriving the arguments for the child node we'd use the wrong method (the getter, instead of the setter). Practically, this only had observably bad results from indexers: indexers without a get method would cause the code to null ref. This is because when deriving the arguments for the getter for non-indexed properties, we'd use the getter, and then immediately bail out because the getter had no arguments. Fixes #45692.

Commit-by-commit review is recommended. Commit 1 nullable enables code so that I could figure out what the bug was. The second commit actually fixes the bug.

…they are object initializers. This only has visible impact on property accesses with arguments on the getter, meaning class indexers.
@AlekseyTs
Copy link
Contributor

AlekseyTs commented Sep 30, 2020

@333fred It looks like there are legitimate CI failures. #Closed

@333fred
Copy link
Member Author

333fred commented Sep 30, 2020

@AlekseyTs should be addressed now.

@dotnet/roslyn-compiler for reviews please.

MethodSymbol accessor = isObjectOrCollectionInitializer ? property.GetOwnOrInheritedGetMethod() : property.GetOwnOrInheritedSetMethod();
var property = (PropertySymbol?)boundObjectInitializerMember.MemberSymbol;
MethodSymbol? accessor = isObjectOrCollectionInitializer ? property.GetOwnOrInheritedGetMethod() : property.GetOwnOrInheritedSetMethod();
Debug.Assert(property is not null);
Copy link
Contributor

@AlekseyTs AlekseyTs Oct 1, 2020

Choose a reason for hiding this comment

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

Debug.Assert(property is not null); [](start = 24, length = 35)

Should the assert be moved right after the declaration of property? It looks like it is dereferenced in the previous statement. #Closed

Copy link
Member Author

Choose a reason for hiding this comment

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

No. Those are extension methods that accept a null input. I could certainly move it, but it doesn't particularly matter.

Copy link
Contributor

Choose a reason for hiding this comment

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

Those are extension methods that accept a null input. I could certainly move it, but it doesn't particularly matter.

I think that would benefit the reader.


In reply to: 497941233 [](ancestors = 497941233)

{
while ((object)property != null)
while (property is not null)
Copy link
Contributor

@AlekseyTs AlekseyTs Oct 1, 2020

Choose a reason for hiding this comment

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

is not [](start = 28, length = 6)

It looks like this PR doesn't follow the general guideline to keep unrelated refactorings out of PRs that change product behavior. Also, in general we prefer avoiding making stylistic changes to existing code. Everybody has personal preferences and if analyzer doesn't flag the code, it is in a good state style/formatting wise. #Closed

Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is an ask mode fix, I would prefer changes like that reverted and keeping this PR to a necessary minimum to address the issue.


In reply to: 497930116 [](ancestors = 497930116)

Copy link
Member Author

Choose a reason for hiding this comment

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

These changes are what allowed me to figure out the bug here. My strategy was to nullable enable the callstack, which allowed me to figure out where the bug was coming from. I'd prefer to keep them.

Copy link
Contributor

Choose a reason for hiding this comment

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

These changes are what allowed me to figure out the bug here. My strategy was to nullable enable the callstack, which allowed me to figure out where the bug was coming from. I'd prefer to keep them.

Changes to comparisons to null and the like are unnecessary. I think they should be reverted and any other changes that are not meant to change product behavior. Nullable annotations and asserts are fine, of course.


In reply to: 497940563 [](ancestors = 497940563)

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Oct 1, 2020

Done with review pass (iteration 3) #Closed

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 (iteration 4)

@ghost
Copy link

ghost commented Oct 1, 2020

Hello @333fred!

Because this pull request has the auto-merge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Auto-approval

@333fred 333fred removed the auto-merge label Oct 1, 2020
@333fred 333fred merged commit eea2313 into dotnet:release/dev16.8 Oct 5, 2020
@333fred 333fred deleted the iop-crash-indexers branch October 5, 2020 18:14
333fred added a commit that referenced this pull request Oct 5, 2020
…elease/dev16.8-to-master

* upstream/release/dev16.8:
  Handle indexers in nested object initializers (#48168)
  Ensure initial binding always binds to natural type (#48205)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants