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

Rename record equality parameters to 'left' and 'right' #51973

Merged
merged 3 commits into from
Mar 20, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ namespace Microsoft.CodeAnalysis.CSharp.Symbols
/// <summary>
/// The record type includes synthesized '==' and '!=' operators equivalent to operators declared as follows:
///
/// public static bool operator==(R? r1, R? r2)
/// => (object) r1 == r2 || ((object)r1 != null &amp;&amp; r1.Equals(r2));
/// public static bool operator !=(R? r1, R? r2)
/// => !(r1 == r2);
/// public static bool operator==(R? left, R? right)
/// => (object) left == right || ((object)left != null &amp;&amp; left.Equals(right));
/// public static bool operator !=(R? left, R? right)
/// => !(left == right);
///
///The 'Equals' method called by the '==' operator is the 'Equals(R? other)' (<see cref="SynthesizedRecordEquals"/>).
///The '!=' operator delegates to the '==' operator. It is an error if the operators are declared explicitly.
Expand All @@ -34,7 +34,7 @@ internal override void GenerateMethodBody(TypeCompilationState compilationState,

try
{
// => (object)r1 == r2 || ((object)r1 != null && r1.Equals(r2));
// => (object)left == right || ((object)left != null && left.Equals(right));
MethodSymbol? equals = null;
foreach (var member in ContainingType.GetMembers(WellKnownMemberNames.ObjectEquals))
{
Expand All @@ -54,12 +54,12 @@ internal override void GenerateMethodBody(TypeCompilationState compilationState,
return;
}

var r1 = F.Parameter(Parameters[0]);
var r2 = F.Parameter(Parameters[1]);
var left = F.Parameter(Parameters[0]);
var right = F.Parameter(Parameters[1]);

BoundExpression objectEqual = F.ObjectEqual(r1, r2);
BoundExpression recordEquals = F.LogicalAnd(F.ObjectNotEqual(r1, F.Null(F.SpecialType(SpecialType.System_Object))),
F.Call(r1, equals, r2));
BoundExpression objectEqual = F.ObjectEqual(left, right);
BoundExpression recordEquals = F.LogicalAnd(F.ObjectNotEqual(left, F.Null(F.SpecialType(SpecialType.System_Object))),
F.Call(left, equals, right));

F.CloseMethod(F.Block(F.Return(F.LogicalOr(objectEqual, recordEquals))));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ namespace Microsoft.CodeAnalysis.CSharp.Symbols
/// <summary>
/// The record type includes synthesized '==' and '!=' operators equivalent to operators declared as follows:
///
/// public static bool operator==(R? r1, R? r2)
/// => (object) r1 == r2 || ((object)r1 != null &amp;&amp; r1.Equals(r2));
/// public static bool operator !=(R? r1, R? r2)
/// => !(r1 == r2);
/// public static bool operator==(R? left, R? right)
/// => (object) left == right || ((object)left != null &amp;&amp; left.Equals(right));
/// public static bool operator !=(R? left, R? right)
/// => !(left == right);
///
///The 'Equals' method called by the '==' operator is the 'Equals(R? other)' (<see cref="SynthesizedRecordEquals"/>).
///The '!=' operator delegates to the '==' operator. It is an error if the operators are declared explicitly.
Expand Down Expand Up @@ -58,10 +58,10 @@ protected sealed override (TypeWithAnnotations ReturnType, ImmutableArray<Parame
Parameters: ImmutableArray.Create<ParameterSymbol>(
new SourceSimpleParameterSymbol(owner: this,
TypeWithAnnotations.Create(ContainingType, NullableAnnotation.Annotated),
ordinal: 0, RefKind.None, "r1", isDiscard: false, Locations),
ordinal: 0, RefKind.None, "left", isDiscard: false, Locations),
C-xC-c marked this conversation as resolved.
Show resolved Hide resolved
new SourceSimpleParameterSymbol(owner: this,
TypeWithAnnotations.Create(ContainingType, NullableAnnotation.Annotated),
ordinal: 1, RefKind.None, "r2", isDiscard: false, Locations)));
ordinal: 1, RefKind.None, "right", isDiscard: false, Locations)));
}

protected override int GetParameterCountFromSyntax() => 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ namespace Microsoft.CodeAnalysis.CSharp.Symbols
/// <summary>
/// The record type includes synthesized '==' and '!=' operators equivalent to operators declared as follows:
///
/// public static bool operator==(R? r1, R? r2)
/// => (object) r1 == r2 || ((object)r1 != null &amp;&amp; r1.Equals(r2));
/// public static bool operator !=(R? r1, R? r2)
/// => !(r1 == r2);
/// public static bool operator==(R? left, R? right)
/// => (object) left == right || ((object)left != null &amp;&amp; left.Equals(right));
/// public static bool operator !=(R? left, R? right)
/// => !(left == right);
///
///The 'Equals' method called by the '==' operator is the 'Equals(R? other)' (<see cref="SynthesizedRecordEquals"/>).
///The '!=' operator delegates to the '==' operator. It is an error if the operators are declared explicitly.
Expand All @@ -35,7 +35,7 @@ internal override void GenerateMethodBody(TypeCompilationState compilationState,

try
{
// => !(r1 == r2);
// => !(left == right);
F.CloseMethod(F.Block(F.Return(F.Not(F.Call(receiver: null, ContainingType.GetMembers(WellKnownMemberNames.EqualityOperatorName).OfType<SynthesizedRecordEqualityOperator>().Single(),
F.Parameter(Parameters[0]), F.Parameter(Parameters[1]))))));
}
Expand Down