Skip to content

Fix crash for Equals analysis of types with bad base clauses#42968

Merged
RikkiGibson merged 3 commits intodotnet:masterfrom
RikkiGibson:equalsmethod-bad-base
Apr 4, 2020
Merged

Fix crash for Equals analysis of types with bad base clauses#42968
RikkiGibson merged 3 commits intodotnet:masterfrom
RikkiGibson:equalsmethod-bad-base

Conversation

@RikkiGibson
Copy link
Member

Closes #42960

Would like to make a pass over NullableWalker to make sure we don't have other bad usages of ReceiverOpt (maybe even enable nullable analysis in NullableWalker?)

@RikkiGibson RikkiGibson requested a review from a team as a code owner March 31, 2020 23:56
.Equals(compilation.GetSpecialTypeMember(SpecialMember.System_Object__Equals));
if (isObjectEqualsMethodOrOverride ||
isWellKnownEqualityMethodOrImplementation(compilation, method, receiverType.Type, WellKnownMember.System_IEquatable_T__Equals))
if (node.ReceiverOpt is BoundExpression receiver &&
Copy link
Member

Choose a reason for hiding this comment

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

nit: Consider putting this additional check in the local function itself

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

LGTM Thanks (iteration 2)

@jcouv jcouv self-assigned this Apr 1, 2020
{
void M(C? other)
{
if (Equals(other)) { other.ToString(); }
Copy link
Contributor

@AlekseyTs AlekseyTs Apr 1, 2020

Choose a reason for hiding this comment

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

Equals(other) [](start = 12, length = 13)

The relationship between the test scenario and the implementation is not obvious. The implementation checks if we have a receiver, what is the relationship with the base type and the lack of the receiver? #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.

I find it surprising as well. It seems like the erroneous base clause causes us to bind the call differently, with a null ReceiverOpt.

I did find that the crash was not produced when calling this.Equals(other). So maybe that would be illustrative to add to the test along with some comment. Or maybe we should go looking in the binder and decide whether the behavior that's happening now is a bug in binding.

Copy link
Contributor

Choose a reason for hiding this comment

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

I find it surprising as well. It seems like the erroneous base clause causes us to bind the call differently, with a null ReceiverOpt.

It is quite possible that binder simply creates an erroneous call node in this case, which doesn't really represent anything that we can learn from (perhaps even the method symbol is an ErrorMethodSymbol). Is this the case? I think IOperation factory detects nodes like that and doesn't even surface them as calls. Consider if we should use the same kind of detection in the nullable walker and bail even earlier than the null check that you added.


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

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 3)

@RikkiGibson RikkiGibson added this to the 16.6.P3 milestone Apr 4, 2020
@RikkiGibson RikkiGibson merged commit 6db969b into dotnet:master Apr 4, 2020
@ghost ghost modified the milestones: 16.6.P3, Next Apr 4, 2020
@RikkiGibson RikkiGibson deleted the equalsmethod-bad-base branch April 4, 2020 00:08
@sharwell sharwell modified the milestones: Next, temp, 16.6.P3 Apr 6, 2020
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.

VS source editing crash when trying to add base class to partial class statement

4 participants