Skip to content

MethodSymbol and FieldSymbol equality fixes:#40939

Closed
chsienki wants to merge 3 commits intodotnet:masterfrom
chsienki:substituted_symbol_equality2
Closed

MethodSymbol and FieldSymbol equality fixes:#40939
chsienki wants to merge 3 commits intodotnet:masterfrom
chsienki:substituted_symbol_equality2

Conversation

@chsienki
Copy link
Copy Markdown
Member

With nullable enabled, it's now valid to compare some method and field symbols across their respective hierarchies.

This PR makes the equals for method and field symbols sealed, and instead contains an explicit list of valid sub-type comparisons. This also requires implementing hashcode for the base method and field symbol. This will potentially have a small perf hit, but should be functionally correct.

- Seal the equals method for field and method symbols, and define the explicitly allowed comparisons
- Add a generic hashcode implementaiton for method and field symbols
- Replace overriden equals methods with a type specific equals
@chsienki chsienki requested a review from a team as a code owner January 13, 2020 22:18
@chsienki chsienki added the PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. label Jan 13, 2020
expectedIncludeNullability: true
);

var method1ParamType = method1.Parameters.First().Type; // A<T!>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please also test the ParameterSymbols directly.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Can you think of a way of getting different parameter symbols, such that one is A and the other A<T!>? I tried to come up with a way, but couldn't.

Do you want me to just break it out and test as is even if we cant?


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

);
}

private void VerifyEquality(ISymbol symbol1, ISymbol symbol2, bool expectedDefault, bool expectedIncludeNullability)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

expectedDefault seems to never be false. Consider either adding negative tests and adjusting hashcode verification accordingly, or removing the parameter.

return (object)other != null && TypeSymbol.Equals(_containingType, other._containingType, compareKind) && OriginalDefinition == other.OriginalDefinition;
}

public override int GetHashCode()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is GetHashCode getting removed here?

return (object)other != null && _reducedFrom.Equals(other._reducedFrom, compareKind);
}

public override int GetHashCode()
Copy link
Copy Markdown
Member

@333fred 333fred Jan 13, 2020

Choose a reason for hiding this comment

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

Why is GetHashCode getting removed here?

var localFunction = symbol as LocalFunctionSymbol;
return (object)localFunction != null
&& localFunction._syntax == _syntax;
return localFunction._syntax == _syntax;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This doesn't seem to take into account the CompareKind, and seems like it will be wrong in the face of substituted nullability. Please add tests to verify that this works as expected.

return (object)other != null &&
_tupleElementIndex == other._tupleElementIndex &&
TypeSymbol.Equals(ContainingType, other.ContainingType, compareKind);
RoslynDebug.Assert(other is object);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please either add these assertions to the other modified Equals methods or remove from this one.

@333fred
Copy link
Copy Markdown
Member

333fred commented Jan 13, 2020

Done review pass (commit 2)

@333fred
Copy link
Copy Markdown
Member

333fred commented Jan 13, 2020

Oh, sorry @chsienki. The github extension for vscode didn't show the PR for Personal Review Only tag, so I didn't notice it until just now.

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

Labels

Area-Compilers PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants