Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -75,6 +75,9 @@ public sealed override bool Equals([NotNullWhen(true)] object? obj)
if (DeclaringType != other.DeclaringType)
Copy link
Contributor

Choose a reason for hiding this comment

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

For the current code, is DeclaringType always the same for every RoSyntheticMethod? It should be RoArrayType. In any case, comparing Declaring type as-is makes sense if RoSyntheticMethod is ever used outside of arrays.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes DeclaringType is always same for every RoSyntheticMethod, need to check it as-is for different array types like int[] vs long[]

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