diff options
author | Michal Strehovsky <michals@microsoft.com> | 2018-08-02 16:57:58 +0300 |
---|---|---|
committer | Michal Strehovsky <michals@microsoft.com> | 2018-08-02 16:57:58 +0300 |
commit | 684bb89d4abeaf71a291414d0b960c2a333c4428 (patch) | |
tree | 442c482357eb26b4a5d6b0acf756d489d175b115 /src/System.Private.Reflection.Core | |
parent | 476627a87b0e348dab5872f6a4da59ff8dca3ca1 (diff) |
Allow illegal custom modifiers on generic constraints
Roslyn decided to do a breaking change to the ECMA-335 file format by generating an illegal custom modifier for the `unmanaged` constraint. The purpose of the modifier is to poison such types for old versions of the C# compiler (the modifier otherwise isn't necessary for the feature to work). This also poisons a lot of the .NET ecosystem too (breaking everything ranging from Mono to the C++/CLI compiler).
We need to update our stack to support this and unblock our customers.
[tfs-changeset: 1709243]
Diffstat (limited to 'src/System.Private.Reflection.Core')
2 files changed, 23 insertions, 1 deletions
diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/General/MetadataReaderExtensions.NativeFormat.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/General/MetadataReaderExtensions.NativeFormat.cs index 901d0f4ba..5896aa812 100644 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/General/MetadataReaderExtensions.NativeFormat.cs +++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/General/MetadataReaderExtensions.NativeFormat.cs @@ -162,6 +162,24 @@ namespace System.Reflection.Runtime.General return customModifiers.ToArray(); } + public static Handle SkipCustomModifiers(this Handle handle, MetadataReader reader) + { + HandleType handleType = handle.HandleType; + Debug.Assert(handleType == HandleType.TypeDefinition || handleType == HandleType.TypeReference || handleType == HandleType.TypeSpecification || handleType == HandleType.ModifiedType); + if (handleType != HandleType.ModifiedType) + return handle; + + do + { + ModifiedType modifiedType = handle.ToModifiedTypeHandle(reader).GetModifiedType(reader); + handle = modifiedType.Type; + handleType = handle.HandleType; + } + while (handleType == HandleType.ModifiedType); + + return handle; + } + public static MethodSignature ParseMethodSignature(this Handle handle, MetadataReader reader) { return handle.ToMethodSignatureHandle(reader).GetMethodSignature(reader); diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/NativeFormat/NativeFormatRuntimeGenericParameterTypeInfo.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/NativeFormat/NativeFormatRuntimeGenericParameterTypeInfo.cs index 678577135..f027f9caa 100644 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/NativeFormat/NativeFormatRuntimeGenericParameterTypeInfo.cs +++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/NativeFormat/NativeFormatRuntimeGenericParameterTypeInfo.cs @@ -81,7 +81,11 @@ namespace System.Reflection.Runtime.TypeInfos.NativeFormat LowLevelList<QTypeDefRefOrSpec> constraints = new LowLevelList<QTypeDefRefOrSpec>(); foreach (Handle constraintHandle in _genericParameter.Constraints) { - constraints.Add(new QTypeDefRefOrSpec(reader, constraintHandle)); + // We're skipping custom modifiers here because Roslyn generates + // a modifier for the "unmanaged" constraint. This doesn't conform to the + // ECMA-335 spec, but we need to deal with it. The modifier is not visible + // to reflection. + constraints.Add(new QTypeDefRefOrSpec(reader, constraintHandle.SkipCustomModifiers(reader))); } return constraints.ToArray(); } |