From 48f9aec9280adf08abba7d1e8ae462682c657787 Mon Sep 17 00:00:00 2001 From: Buyaa Namnan Date: Wed, 3 Nov 2021 12:09:12 -0700 Subject: [PATCH] Use constant ids for RoArrayType GetMethodsCore --- .../TypeLoading/Methods/RoSyntheticMethod.cs | 3 --- .../Reflection/TypeLoading/Types/RoArrayType.cs | 7 +++---- .../tests/src/Tests/Type/TypeTests.cs | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 7 deletions(-) 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 af4d205d6cc3a..efba722ec3454 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,9 +75,6 @@ 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/src/System/Reflection/TypeLoading/Types/RoArrayType.cs b/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/Types/RoArrayType.cs index 44afe732339e7..40de13e519cd2 100644 --- a/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/Types/RoArrayType.cs +++ b/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/Types/RoArrayType.cs @@ -151,7 +151,6 @@ internal sealed override IEnumerable GetMethodsCore(NameFilter? filt { int rank = _rank; - int uniquifier = 0; RoType systemInt32 = Loader.GetCoreType(CoreType.Int32); RoType elementType = GetRoElementType(); RoType systemVoid = Loader.GetCoreType(CoreType.Void); @@ -163,7 +162,7 @@ internal sealed override IEnumerable GetMethodsCore(NameFilter? filt { getParameters[i] = systemInt32; } - yield return new RoSyntheticMethod(this, uniquifier++, "Get", elementType, getParameters); + yield return new RoSyntheticMethod(this, 0, "Get", elementType, getParameters); } if (filter == null || filter.Matches("Set")) @@ -174,7 +173,7 @@ internal sealed override IEnumerable GetMethodsCore(NameFilter? filt setParameters[i] = systemInt32; } setParameters[rank] = elementType; - yield return new RoSyntheticMethod(this, uniquifier++, "Set", systemVoid, setParameters); + yield return new RoSyntheticMethod(this, 1, "Set", systemVoid, setParameters); } if (filter == null || filter.Matches("Address")) @@ -184,7 +183,7 @@ internal sealed override IEnumerable GetMethodsCore(NameFilter? filt { addressParameters[i] = systemInt32; } - yield return new RoSyntheticMethod(this, uniquifier++, "Address", elementType.GetUniqueByRefType(), addressParameters); + yield return new RoSyntheticMethod(this, 2, "Address", elementType.GetUniqueByRefType(), addressParameters); } } } 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 dd4d0e171a385..bb9f1775d2fff 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 @@ -251,6 +251,20 @@ void testEqual(Type type1, Type type2) testEqual(typeof(long[]).Project(), typeof(long[]).Project()); } + [Fact] + static void TestArrayGetMethodsResultEqualsFilteredGetMethod() + { + Type type = typeof(int[]).Project(); + + Assert.Equal(type.GetMethod("Get"), type.GetMethods().First(m => m.Name == "Get")); + Assert.Equal(type.GetMethod("Set"), type.GetMethods().First(m => m.Name == "Set")); + Assert.Equal(type.GetMethod("Address"), type.GetMethods().First(m => m.Name == "Address")); + + Assert.NotEqual(type.GetMethod("Get"), type.GetMethods().First(m => m.Name == "Set")); + Assert.NotEqual(type.GetMethod("Set"), type.GetMethods().First(m => m.Name == "Address")); + Assert.NotEqual(type.GetMethod("Address"), type.GetMethods().First(m => m.Name == "Get")); + } + [Fact] public static void TestArrayAddressMethod() {