Skip to content

Commit

Permalink
Rename record equality parameters to 'left' and 'right' (#51973)
Browse files Browse the repository at this point in the history
Co-authored-by: Jack Tyrer <[email protected]>
  • Loading branch information
C-xC-c and C-xC-c authored Mar 20, 2021
1 parent 9f2d705 commit 791d60f
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 49 deletions.
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),
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
Original file line number Diff line number Diff line change
Expand Up @@ -2542,8 +2542,8 @@ void M() { }
"void C.M()",
"System.String C.ToString()",
"System.Boolean C." + WellKnownMemberNames.PrintMembersMethodName + "(System.Text.StringBuilder builder)",
"System.Boolean C.op_Inequality(C? r1, C? r2)",
"System.Boolean C.op_Equality(C? r1, C? r2)",
"System.Boolean C.op_Inequality(C? left, C? right)",
"System.Boolean C.op_Equality(C? left, C? right)",
"System.Int32 C.GetHashCode()",
"System.Boolean C.Equals(System.Object? obj)",
"System.Boolean C.Equals(C? other)",
Expand Down
48 changes: 24 additions & 24 deletions src/Compilers/CSharp/Test/Semantic/Semantics/RecordTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ void M(RecordA a, RecordB b)
var tree = comp.SyntaxTrees.First();
var model = comp.GetSemanticModel(tree, ignoreAccessibility: false);
var node = tree.GetRoot().DescendantNodes().OfType<BinaryExpressionSyntax>().Single();
Assert.Equal("System.Boolean RecordB.op_Equality(RecordB? r1, RecordB? r2)",
Assert.Equal("System.Boolean RecordB.op_Equality(RecordB? left, RecordB? right)",
model.GetSymbolInfo(node).Symbol.ToTestDisplayString());
}

Expand All @@ -287,7 +287,7 @@ public record RecordB();
";
var comp = CreateCompilation(src);
var b = comp.GlobalNamespace.GetTypeMember("RecordB");
AssertEx.SetEqual(new[] { "System.Boolean RecordB.op_Equality(RecordB? r1, RecordB? r2)" },
AssertEx.SetEqual(new[] { "System.Boolean RecordB.op_Equality(RecordB? left, RecordB? right)" },
b.GetSimpleNonTypeMembers("op_Equality").ToTestDisplayStrings());
}

Expand Down Expand Up @@ -1023,8 +1023,8 @@ public void set_X() { }
"System.Int32 C.set_Y(System.Int32 value)",
"System.String C.ToString()",
"System.Boolean C." + WellKnownMemberNames.PrintMembersMethodName + "(System.Text.StringBuilder builder)",
"System.Boolean C.op_Inequality(C? r1, C? r2)",
"System.Boolean C.op_Equality(C? r1, C? r2)",
"System.Boolean C.op_Inequality(C? left, C? right)",
"System.Boolean C.op_Equality(C? left, C? right)",
"System.Int32 C.GetHashCode()",
"System.Boolean C.Equals(System.Object? obj)",
"System.Boolean C.Equals(C? other)",
Expand Down Expand Up @@ -1468,8 +1468,8 @@ .maxstack 1
"System.Type C.EqualityContract { get; }",
"System.String C.ToString()",
"System.Boolean C." + WellKnownMemberNames.PrintMembersMethodName + "(System.Text.StringBuilder builder)",
"System.Boolean C.op_Inequality(C? r1, C? r2)",
"System.Boolean C.op_Equality(C? r1, C? r2)",
"System.Boolean C.op_Inequality(C? left, C? right)",
"System.Boolean C.op_Equality(C? left, C? right)",
"System.Int32 C.GetHashCode()",
"System.Boolean C.Equals(System.Object? obj)",
"System.Boolean C.Equals(C? other)",
Expand Down Expand Up @@ -9706,8 +9706,8 @@ public void Inheritance_09()
"System.Int32 C.Y.get",
"System.String C.ToString()",
"System.Boolean C." + WellKnownMemberNames.PrintMembersMethodName + "(System.Text.StringBuilder builder)",
"System.Boolean C.op_Inequality(C? r1, C? r2)",
"System.Boolean C.op_Equality(C? r1, C? r2)",
"System.Boolean C.op_Inequality(C? left, C? right)",
"System.Boolean C.op_Equality(C? left, C? right)",
"System.Int32 C.GetHashCode()",
"System.Boolean C.Equals(System.Object? obj)",
"System.Boolean C.Equals(C? other)",
Expand Down Expand Up @@ -10391,8 +10391,8 @@ record C(object P)
"System.Object B.Q { get; init; }",
"System.String B.ToString()",
"System.Boolean B." + WellKnownMemberNames.PrintMembersMethodName + "(System.Text.StringBuilder builder)",
"System.Boolean B.op_Inequality(B? r1, B? r2)",
"System.Boolean B.op_Equality(B? r1, B? r2)",
"System.Boolean B.op_Inequality(B? left, B? right)",
"System.Boolean B.op_Equality(B? left, B? right)",
"System.Int32 B.GetHashCode()",
"System.Boolean B.Equals(System.Object? obj)",
"System.Boolean B.Equals(A? other)",
Expand All @@ -10416,8 +10416,8 @@ record C(object P)
"System.Object C.set_Q()",
"System.String C.ToString()",
"System.Boolean C." + WellKnownMemberNames.PrintMembersMethodName + "(System.Text.StringBuilder builder)",
"System.Boolean C.op_Inequality(C? r1, C? r2)",
"System.Boolean C.op_Equality(C? r1, C? r2)",
"System.Boolean C.op_Inequality(C? left, C? right)",
"System.Boolean C.op_Equality(C? left, C? right)",
"System.Int32 C.GetHashCode()",
"System.Boolean C.Equals(System.Object? obj)",
"System.Boolean C.Equals(C? other)",
Expand Down Expand Up @@ -15380,8 +15380,8 @@ record B(int X, int Y) : A
"System.Int32 B.Y { get; init; }",
"System.String B.ToString()",
"System.Boolean B." + WellKnownMemberNames.PrintMembersMethodName + "(System.Text.StringBuilder builder)",
"System.Boolean B.op_Inequality(B? r1, B? r2)",
"System.Boolean B.op_Equality(B? r1, B? r2)",
"System.Boolean B.op_Inequality(B? left, B? right)",
"System.Boolean B.op_Equality(B? left, B? right)",
"System.Int32 B.GetHashCode()",
"System.Boolean B.Equals(System.Object? obj)",
"System.Boolean B.Equals(A? other)",
Expand Down Expand Up @@ -15432,8 +15432,8 @@ record B(int X, int Y) : A
"System.Int32 B.Y { get; init; }",
"System.String B.ToString()",
"System.Boolean B." + WellKnownMemberNames.PrintMembersMethodName + "(System.Text.StringBuilder builder)",
"System.Boolean B.op_Inequality(B? r1, B? r2)",
"System.Boolean B.op_Equality(B? r1, B? r2)",
"System.Boolean B.op_Inequality(B? left, B? right)",
"System.Boolean B.op_Equality(B? left, B? right)",
"System.Int32 B.GetHashCode()",
"System.Boolean B.Equals(System.Object? obj)",
"System.Boolean B.Equals(A? other)",
Expand Down Expand Up @@ -19937,7 +19937,7 @@ True True False False

var comp = (CSharpCompilation)verifier.Compilation;
MethodSymbol op = comp.GetMembers("A." + WellKnownMemberNames.EqualityOperatorName).OfType<SynthesizedRecordEqualityOperator>().Single();
Assert.Equal("System.Boolean A.op_Equality(A? r1, A? r2)", op.ToTestDisplayString());
Assert.Equal("System.Boolean A.op_Equality(A? left, A? right)", op.ToTestDisplayString());
Assert.Equal(Accessibility.Public, op.DeclaredAccessibility);
Assert.True(op.IsStatic);
Assert.False(op.IsAbstract);
Expand All @@ -19947,7 +19947,7 @@ True True False False
Assert.True(op.IsImplicitlyDeclared);

op = comp.GetMembers("A." + WellKnownMemberNames.InequalityOperatorName).OfType<SynthesizedRecordInequalityOperator>().Single();
Assert.Equal("System.Boolean A.op_Inequality(A? r1, A? r2)", op.ToTestDisplayString());
Assert.Equal("System.Boolean A.op_Inequality(A? left, A? right)", op.ToTestDisplayString());
Assert.Equal(Accessibility.Public, op.DeclaredAccessibility);
Assert.True(op.IsStatic);
Assert.False(op.IsAbstract);
Expand Down Expand Up @@ -20056,7 +20056,7 @@ False False True True

var comp = (CSharpCompilation)verifier.Compilation;
MethodSymbol op = comp.GetMembers("A." + WellKnownMemberNames.EqualityOperatorName).OfType<SynthesizedRecordEqualityOperator>().Single();
Assert.Equal("System.Boolean A.op_Equality(A? r1, A? r2)", op.ToTestDisplayString());
Assert.Equal("System.Boolean A.op_Equality(A? left, A? right)", op.ToTestDisplayString());
Assert.Equal(Accessibility.Public, op.DeclaredAccessibility);
Assert.True(op.IsStatic);
Assert.False(op.IsAbstract);
Expand All @@ -20066,7 +20066,7 @@ False False True True
Assert.True(op.IsImplicitlyDeclared);

op = comp.GetMembers("A." + WellKnownMemberNames.InequalityOperatorName).OfType<SynthesizedRecordInequalityOperator>().Single();
Assert.Equal("System.Boolean A.op_Inequality(A? r1, A? r2)", op.ToTestDisplayString());
Assert.Equal("System.Boolean A.op_Inequality(A? left, A? right)", op.ToTestDisplayString());
Assert.Equal(Accessibility.Public, op.DeclaredAccessibility);
Assert.True(op.IsStatic);
Assert.False(op.IsAbstract);
Expand Down Expand Up @@ -23145,8 +23145,8 @@ record C : B;
"System.Type B.EqualityContract.get",
"System.String B.ToString()",
"System.Boolean B." + WellKnownMemberNames.PrintMembersMethodName + "(System.Text.StringBuilder builder)",
"System.Boolean B.op_Inequality(B? r1, B? r2)",
"System.Boolean B.op_Equality(B? r1, B? r2)",
"System.Boolean B.op_Inequality(B? left, B? right)",
"System.Boolean B.op_Equality(B? left, B? right)",
"System.Int32 B.GetHashCode()",
"System.Boolean B.Equals(System.Object? obj)",
"System.Boolean B.Equals(A? other)",
Expand Down Expand Up @@ -23293,8 +23293,8 @@ static void Main()
"System.Int32 B1.P { get; init; }",
"System.String B1.ToString()",
"System.Boolean B1." + WellKnownMemberNames.PrintMembersMethodName + "(System.Text.StringBuilder builder)",
"System.Boolean B1.op_Inequality(B1? r1, B1? r2)",
"System.Boolean B1.op_Equality(B1? r1, B1? r2)",
"System.Boolean B1.op_Inequality(B1? left, B1? right)",
"System.Boolean B1.op_Equality(B1? left, B1? right)",
"System.Int32 B1.GetHashCode()",
"System.Boolean B1.Equals(System.Object? obj)",
"System.Boolean B1.Equals(A? other)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1139,8 +1139,8 @@ record C
"void C.Y.init",
"System.String C.ToString()",
"System.Boolean C." + WellKnownMemberNames.PrintMembersMethodName + "(System.Text.StringBuilder! builder)",
"System.Boolean C.operator !=(C? r1, C? r2)",
"System.Boolean C.operator ==(C? r1, C? r2)",
"System.Boolean C.operator !=(C? left, C? right)",
"System.Boolean C.operator ==(C? left, C? right)",
"System.Int32 C.GetHashCode()",
"System.Boolean C.Equals(System.Object? obj)",
"System.Boolean C.Equals(C? other)",
Expand Down

0 comments on commit 791d60f

Please sign in to comment.