Skip to content

Commit 3f57855

Browse files
committed
Fixed creating generic type with abstract type when it is has a default constructor constraint
1 parent 7dc3669 commit 3f57855

4 files changed

Lines changed: 4 additions & 4 deletions

File tree

src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/TypeLoader/ConstraintValidator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ private static bool SatisfiesConstraints(this Type genericVariable, SigTypeConte
3838

3939
if ((attributes & GenericParameterAttributes.DefaultConstructorConstraint) != 0)
4040
{
41-
if (!typeArg.HasExplicitOrImplicitPublicDefaultConstructor())
41+
if (!typeArg.HasExplicitOrImplicitPublicDefaultConstructor() || typeArg.IsAbstract)
4242
return false;
4343
}
4444

src/coreclr/vm/typedesc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1464,7 +1464,7 @@ BOOL TypeVarTypeDesc::SatisfiesConstraints(SigTypeContext *pTypeContextOfConstra
14641464

14651465
if ((specialConstraints & gpDefaultConstructorConstraint) != 0)
14661466
{
1467-
if (thArg.IsTypeDesc() || (!thArg.AsMethodTable()->HasExplicitOrImplicitPublicDefaultConstructor()))
1467+
if (thArg.IsTypeDesc() || (!thArg.AsMethodTable()->HasExplicitOrImplicitPublicDefaultConstructor() || thArg.IsAbstract()))
14681468
return FALSE;
14691469
}
14701470

src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/ReflectionModel/GenericServices.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public static bool CanSpecialize(Type type, GenericParameterAttributes attribute
178178
if ((attributes & GenericParameterAttributes.DefaultConstructorConstraint) != 0)
179179
{
180180
// value types always have default constructors
181-
if (!type.IsValueType && (type.GetConstructor(Type.EmptyTypes) == null))
181+
if (!type.IsValueType && ((type.GetConstructor(Type.EmptyTypes) == null) || type.IsAbstract))
182182
{
183183
return false;
184184
}

src/mono/mono/metadata/verify.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ is_valid_generic_instantiation (MonoGenericContainer *gc, MonoGenericContext *co
9999
if ((param_info->flags & GENERIC_PARAMETER_ATTRIBUTE_REFERENCE_TYPE_CONSTRAINT) && m_class_is_valuetype (paramClass))
100100
return FALSE;
101101

102-
if ((param_info->flags & GENERIC_PARAMETER_ATTRIBUTE_CONSTRUCTOR_CONSTRAINT) && !m_class_is_valuetype (paramClass) && !mono_class_has_default_constructor (paramClass, TRUE))
102+
if ((param_info->flags & GENERIC_PARAMETER_ATTRIBUTE_CONSTRUCTOR_CONSTRAINT) && !m_class_is_valuetype (paramClass) && (!mono_class_has_default_constructor (paramClass, TRUE) || mono_class_is_abstract(paramClass)))
103103
return FALSE;
104104

105105
if (!param_info->constraints)

0 commit comments

Comments
 (0)