From 19bb2eaf3b7ff8ff3839f85e0ea9425ca51f40ae Mon Sep 17 00:00:00 2001 From: Kouji Matsui Date: Wed, 20 Oct 2021 20:54:18 +0900 Subject: [PATCH] Fixed devirtualization at matching between standard method and explicitly implemented interface method. #104 https://github.com/kekyo/IL2C/pull/104#pullrequestreview-782054327 --- IL2C.Core/Metadata/MetadataUtilities.cs | 32 ++++++++++++++----------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/IL2C.Core/Metadata/MetadataUtilities.cs b/IL2C.Core/Metadata/MetadataUtilities.cs index 014ac45c..13acaeae 100644 --- a/IL2C.Core/Metadata/MetadataUtilities.cs +++ b/IL2C.Core/Metadata/MetadataUtilities.cs @@ -473,27 +473,31 @@ public int Compare(IMethodInformation x, IMethodInformation y) public bool Equals(IMethodInformation x, IMethodInformation y) { - var xname = x.Name; - var yname = y.Name; - - if (xname != yname) + // Try strictly matching when both class/value type member method + // and explicitly implemented interface method are same. + if (!x.DeclaringType.IsInterface && y.DeclaringType.IsInterface) { - // If it is an explicit interface implementation, we need to compare with it's full name - if (x.DeclaringType.IsInterface) + if (x.Overrides.Contains(y)) { - xname = $"{x.DeclaringType.FriendlyName}.{xname}"; - } - if (y.DeclaringType.IsInterface) - { - yname = $"{y.DeclaringType.FriendlyName}.{yname}"; + return true; } - - if (xname != yname) + } + if (x.DeclaringType.IsInterface && !y.DeclaringType.IsInterface) + { + if (y.Overrides.Contains(x)) { - return false; + return true; } } + var xname = x.Name; + var yname = y.Name; + + if (xname != yname) + { + return false; + } + var xps = x.Parameters; var yps = y.Parameters;