From 505a2a23fc883d9fd2c87555f5ce316227c33661 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Fri, 14 May 2021 16:17:48 -0700 Subject: [PATCH] Remove from hashtable as we return from HasOnlyBlittableFields to make sure we're handling our recursion check correctly. --- .../TypeSymbolExtensions.cs | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/DllImportGenerator/DllImportGenerator/TypeSymbolExtensions.cs b/DllImportGenerator/DllImportGenerator/TypeSymbolExtensions.cs index 1db9eb33336c..4d854c904463 100644 --- a/DllImportGenerator/DllImportGenerator/TypeSymbolExtensions.cs +++ b/DllImportGenerator/DllImportGenerator/TypeSymbolExtensions.cs @@ -29,26 +29,30 @@ private static bool HasOnlyBlittableFields(this ITypeSymbol type, HashSet()) { - bool? fieldBlittable = field switch + if (!field.IsStatic) { - { IsStatic: true } => null, - { Type: { IsReferenceType: true } } => false, - { Type: IPointerTypeSymbol ptr } => IsConsideredBlittable(ptr.PointedAtType), - { Type: IFunctionPointerTypeSymbol } => true, - not { Type: { SpecialType: SpecialType.None } } => IsSpecialTypeBlittable(field.Type.SpecialType), - // Assume that type parameters that can be blittable are blittable. - // We'll re-evaluate blittability for generic fields of generic types at instantation time. - { Type: ITypeParameterSymbol } => true, - { Type: { IsValueType: false } } => false, - _ => IsConsideredBlittable(field.Type, seenTypes) - }; - - if (fieldBlittable is false) - { - return false; + bool fieldBlittable = field switch + { + { Type: { IsReferenceType: true } } => false, + { Type: IPointerTypeSymbol ptr } => IsConsideredBlittable(ptr.PointedAtType), + { Type: IFunctionPointerTypeSymbol } => true, + not { Type: { SpecialType: SpecialType.None } } => IsSpecialTypeBlittable(field.Type.SpecialType), + // Assume that type parameters that can be blittable are blittable. + // We'll re-evaluate blittability for generic fields of generic types at instantation time. + { Type: ITypeParameterSymbol } => true, + { Type: { IsValueType: false } } => false, + _ => IsConsideredBlittable(field.Type, seenTypes) + }; + + if (!fieldBlittable) + { + seenTypes.Remove(type); + return false; + } } } + seenTypes.Remove(type); return true; } @@ -98,7 +102,7 @@ private static bool IsConsideredBlittable(this ITypeSymbol type, HashSet