From a9f6c46cc85d5ed873eb6d5277ab5b4097d9d48b Mon Sep 17 00:00:00 2001 From: Tomas Date: Mon, 26 Apr 2021 21:12:04 +0200 Subject: [PATCH] Add support for covariant return types for virtual static interface methods --- src/coreclr/vm/methodtablebuilder.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/coreclr/vm/methodtablebuilder.cpp b/src/coreclr/vm/methodtablebuilder.cpp index 6231a4e074ab47..49652674a062f3 100644 --- a/src/coreclr/vm/methodtablebuilder.cpp +++ b/src/coreclr/vm/methodtablebuilder.cpp @@ -2114,9 +2114,9 @@ BOOL MethodTableBuilder::IsEligibleForCovariantReturns(mdToken methodDeclToken) // // Note on covariant return types: right now we only support covariant returns for MethodImpls on - // classes, where the MethodDecl is also on a class. Interface methods are not supported. - // We will also allow covariant return types if both the MethodImpl and MethodDecl are not on the same type. - // + // classes, where the MethodDecl is also on a class. Interface methods are not supported except for static + // virtual methods. We will also allow covariant return types if both the MethodImpl and MethodDecl + // are not on the same type. HRESULT hr = S_OK; IMDInternalImport* pMDInternalImport = GetMDImport(); @@ -2181,7 +2181,21 @@ BOOL MethodTableBuilder::IsEligibleForCovariantReturns(mdToken methodDeclToken) if (FAILED(hr)) BuildMethodTableThrowException(hr, *bmtError); - return !IsTdInterface(attr); + if (!IsTdInterface(attr)) + { + return TRUE; + } + + hr = pMDInternalImport->GetMethodDefProps(methodDeclToken, &attr); + if (FAILED(hr)) + BuildMethodTableThrowException(hr, *bmtError); + + if (IsMdStatic(attr)) + { + return TRUE; + } + + return FALSE; } //*******************************************************************************