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