Skip to content

Commit

Permalink
Fix Equals overload logic for some methods of an array created using …
Browse files Browse the repository at this point in the history
…MLC (#60894)
  • Loading branch information
buyaa-n authored Oct 28, 2021
1 parent efdd9a6 commit 5613572
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ public sealed override bool Equals([NotNullWhen(true)] object? obj)
if (DeclaringType != other.DeclaringType)
return false;

if (ReturnType != other.ReturnType)
return false;

if (_uniquifier != other._uniquifier)
return false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,49 @@ public static void TestArraySetMethod()
return;
}

[Fact]
static void TestArrayMethodsGetSetAddressAreNotEquals()
{
void test(Type type)
{
MethodInfo v1 = type.GetMethod("Get");
MethodInfo v2 = type.GetMethod("Set");
MethodInfo v3 = type.GetMethod("Address");
Assert.NotEqual(v1, v2);
Assert.NotEqual(v1, v3);
Assert.NotEqual(v2, v3);
}

test(typeof(int[]));
test(typeof(int[]).Project());
}

[Fact]
static void TestArrayMethodsGetSetAddressEqualityForDifferentTypes()
{
void testNotEqual(Type type1, Type type2)
{
Assert.NotEqual(type1.GetMethod("Get"), type2.GetMethod("Get"));
Assert.NotEqual(type1.GetMethod("Set"), type2.GetMethod("Set"));
Assert.NotEqual(type1.GetMethod("Address"), type2.GetMethod("Address"));
}

testNotEqual(typeof(int[]), typeof(long[]));
testNotEqual(typeof(int[]).Project(), typeof(long[]).Project());
testNotEqual(typeof(int[]).Project(), typeof(int[]));

void testEqual(Type type1, Type type2)
{
Assert.Equal(type1.GetMethod("Get"), type2.GetMethod("Get"));
Assert.Equal(type1.GetMethod("Set"), type2.GetMethod("Set"));
Assert.Equal(type1.GetMethod("Address"), type2.GetMethod("Address"));
}

testEqual(typeof(int[]), typeof(int[]));
testEqual(typeof(int[]).Project(), typeof(int[]).Project());
testEqual(typeof(long[]).Project(), typeof(long[]).Project());
}

[Fact]
public static void TestArrayAddressMethod()
{
Expand Down

0 comments on commit 5613572

Please sign in to comment.