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
24 changes: 24 additions & 0 deletions src/coreclr/vm/typedesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1903,6 +1903,30 @@ BOOL TypeVarTypeDesc::SatisfiesConstraints(SigTypeContext *pTypeContextOfConstra
// if a concrete type can be cast to the constraint, then this constraint will be satisifed
if (thElem.CanCastTo(thConstraint))
{
// Static virtual methods need an extra check when an abstract type is used for instantiation
// to ensure that the implementation of the constraint is complete
if (!thElem.IsTypeDesc() &&
thElem.AsMethodTable()->IsAbstract() &&
thConstraint.IsInterface() &&
thConstraint.AsMethodTable()->HasVirtualStaticMethods())
{
MethodTable *pInterfaceMT = thConstraint.AsMethodTable();
bool virtualStaticResolutionCheckFailed = false;
for (MethodTable::MethodIterator it(pInterfaceMT); it.IsValid(); it.Next())
{
MethodDesc *pMD = it.GetMethodDesc();
if (pMD->IsVirtual() &&
pMD->IsStatic() &&
!thElem.AsMethodTable()->ResolveVirtualStaticMethod(pInterfaceMT, pMD, /* allowNullResult */ TRUE, /* checkDuplicates */ TRUE))
{
virtualStaticResolutionCheckFailed = true;
break;
}
}

if (virtualStaticResolutionCheckFailed)
continue;
}
fCanCast = TRUE;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,14 @@ ConstrainedCallOnAbstractClassToAbstractMethodOnSharedGenericDone: nop
.try {
call void TestEntrypoint::TestScenario2Wrapper()
ldstr "ConstraintCheckShouldFail"
ldstr "TypeLoadException"
ldstr "VerificationException"
ldstr "Did not throw exception"
call void [TypeHierarchyCommonCs]Statics::CheckForFailure(string,string,string)
leave.s ConstraintCheckShouldFailDone
} catch [System.Runtime]System.Exception {
stloc.0
ldstr "ConstraintCheckShouldFail"
ldstr "TypeLoadException"
ldstr "VerificationException"
ldloc.0
callvirt instance class [System.Runtime]System.Type [System.Runtime]System.Exception::GetType()
callvirt instance string [System.Runtime]System.Reflection.MemberInfo::get_Name()
Expand Down