Skip to content

Commit

Permalink
Fix constraint check when a type variable is used to instantiate a ge…
Browse files Browse the repository at this point in the history
…neric argument (#22)
  • Loading branch information
davidwrighton authored May 13, 2021
1 parent 9495cbf commit c9e4403
Show file tree
Hide file tree
Showing 3 changed files with 583 additions and 578 deletions.
7 changes: 6 additions & 1 deletion src/coreclr/vm/typedesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1905,7 +1905,12 @@ BOOL TypeVarTypeDesc::SatisfiesConstraints(SigTypeContext *pTypeContextOfConstra
{
// 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() &&
//
// Do not apply this check when the generic argument is exactly a generic variable, as those
// do not hold the correct detail for checking, and do not need to do so. This constraint rule
// is only applicable for generic arguments which have been specialized to some extent
if (!thArg.IsGenericVariable() &&
!thElem.IsTypeDesc() &&
thElem.AsMethodTable()->IsAbstract() &&
thConstraint.IsInterface() &&
thConstraint.AsMethodTable()->HasVirtualStaticMethods())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ static void Main(string[] args)
break;

case CallerMethodScenario.GenericOverConstrainedType:
mdIndividualTestMethod.Name = $"{mdIndividualTestMethod.Name}<(class {CommonPrefix}IFaceGeneric`1<!!U>, {CommonPrefix}IFaceNonGeneric, class {CommonPrefix}IFaceCuriouslyRecurringGeneric`1<!!T>) T,U>";
mdIndividualTestMethod.Name = $"{mdIndividualTestMethod.Name}<({(interfaceTypeSansImplPrefix.Contains("`") ? "class " : "")}{CommonPrefix}{interfaceTypeSansImplPrefix}) T,U>";

expectedString = expectedString.Replace("!!0", $"{constrainedTypePrefix}{constrainedType}");
expectedString = expectedString.Replace(ImplPrefix, "");
Expand Down
Loading

0 comments on commit c9e4403

Please sign in to comment.