diff --git a/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/Methods/RoSyntheticMethod.cs b/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/Methods/RoSyntheticMethod.cs index efba722ec34544..af4d205d6cc3a1 100644 --- a/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/Methods/RoSyntheticMethod.cs +++ b/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/Methods/RoSyntheticMethod.cs @@ -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; diff --git a/src/libraries/System.Reflection.MetadataLoadContext/tests/src/Tests/Type/TypeTests.cs b/src/libraries/System.Reflection.MetadataLoadContext/tests/src/Tests/Type/TypeTests.cs index 09e5d783fd4bf5..dd4d0e171a3857 100644 --- a/src/libraries/System.Reflection.MetadataLoadContext/tests/src/Tests/Type/TypeTests.cs +++ b/src/libraries/System.Reflection.MetadataLoadContext/tests/src/Tests/Type/TypeTests.cs @@ -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() {