diff options
author | Michal Strehovský <MichalStrehovsky@users.noreply.github.com> | 2017-05-03 02:51:09 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-03 02:51:09 +0300 |
commit | 29d330e0d46d21053ab3aeb0ffe37fc7e3128851 (patch) | |
tree | e07d4df2d28d1de0b1a98b0cae8e64304eb85c0a /src/System.Private.Reflection.Execution | |
parent | 97b1584074fc1244a57c33f15fbe55610d5bacdb (diff) |
Don't ask the type loader to build instantiations over generic type definitions (#3478)
Found in CoreFX tests.
Diffstat (limited to 'src/System.Private.Reflection.Execution')
3 files changed, 13 insertions, 8 deletions
diff --git a/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/ExecutionEnvironmentImplementation.MappingTables.cs b/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/ExecutionEnvironmentImplementation.MappingTables.cs index 9d058df01..895f7651b 100644 --- a/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/ExecutionEnvironmentImplementation.MappingTables.cs +++ b/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/ExecutionEnvironmentImplementation.MappingTables.cs @@ -227,7 +227,8 @@ namespace Internal.Reflection.Execution { if (RuntimeAugments.IsGenericTypeDefinition(elementTypeHandle)) { - throw new NotSupportedException(SR.NotSupported_OpenType); + arrayTypeHandle = default(RuntimeTypeHandle); + return false; } // For non-dynamic arrays try to look up the array type in the ArrayMap blobs; @@ -263,7 +264,8 @@ namespace Internal.Reflection.Execution { if (RuntimeAugments.IsGenericTypeDefinition(elementTypeHandle)) { - throw new NotSupportedException(SR.NotSupported_OpenType); + arrayTypeHandle = default(RuntimeTypeHandle); + return false; } if ((rank < MDArray.MinRank) || (rank > MDArray.MaxRank)) @@ -343,7 +345,16 @@ namespace Internal.Reflection.Execution TypeInfo[] typeArguments = new TypeInfo[genericTypeArgumentHandles.Length]; for (int i = 0; i < genericTypeArgumentHandles.Length; i++) + { + // Early out if one of the arguments is a generic definition. + // The reflection stack will use this to construct a Type that doesn't have a type handle. + // Note: this is different from the validation we do in EnsureSatisfiesClassConstraints because this + // should not throw. + if (RuntimeAugments.IsGenericTypeDefinition(genericTypeArgumentHandles[i])) + return false; + typeArguments[i] = Type.GetTypeFromHandle(genericTypeArgumentHandles[i]).GetTypeInfo(); + } ConstraintValidator.EnsureSatisfiesClassConstraints(typeDefinition, typeArguments); diff --git a/src/System.Private.Reflection.Execution/src/Resources/Resources.resx b/src/System.Private.Reflection.Execution/src/Resources/Resources.resx index ed51ff74b..6d4210f7e 100644 --- a/src/System.Private.Reflection.Execution/src/Resources/Resources.resx +++ b/src/System.Private.Reflection.Execution/src/Resources/Resources.resx @@ -201,9 +201,6 @@ <data name="Argument_ConstraintFailed" xml:space="preserve"> <value>'{0}', on '{1}' violates the constraint of type '{2}'.</value> </data> - <data name="NotSupported_OpenType" xml:space="preserve"> - <value>Cannot create arrays of open type. </value> - </data> <data name="PlatformNotSupported_GetMethodInfoForStubDelegate" xml:space="preserve"> <value>Obtaining a MethodInfo of a reflection-constructed delegate to a virtual method is not supported on this platform.</value> </data> diff --git a/src/System.Private.Reflection.Execution/src/Resources/Strings.resx b/src/System.Private.Reflection.Execution/src/Resources/Strings.resx index 028ba1076..905717d33 100644 --- a/src/System.Private.Reflection.Execution/src/Resources/Strings.resx +++ b/src/System.Private.Reflection.Execution/src/Resources/Strings.resx @@ -198,9 +198,6 @@ <data name="Argument_ConstraintFailed" xml:space="preserve"> <value>'{0}', on '{1}' violates the constraint of type '{2}'.</value> </data> - <data name="NotSupported_OpenType" xml:space="preserve"> - <value>Cannot create arrays of open type. </value> - </data> <data name="PlatformNotSupported_GetMethodInfoForStubDelegate" xml:space="preserve"> <value>Obtaining a MethodInfo of a reflection-constructed delegate to a virtual method is not supported on this platform.</value> </data> |