Skip to content

Commit d361507

Browse files
Do not say the wrong default behavior for blittable arrays in ComInterfaceGenerator warning (#88212)
The warning used to say the default is [In] for blittable arrays, when the default is [In, Out]. Reworks how Unnecessary / Not supported / supported [In, Out] diagnostic reporting is implemented. Each marshaller will decide which details are provided with the diagnostic and which attributes are unnecessary. Shares a single Strings.resx with all projects. "Com" or "LibraryImport" suffixes were added to string names that conflicted. Co-authored-by: Jeremy Koritzinsky <jekoritz@microsoft.com>
1 parent 620bd3e commit d361507

File tree

87 files changed

+17787
-17877
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+17787
-17877
lines changed

src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2597,11 +2597,11 @@
25972597
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\PortableThreadPool.Windows.cs" Condition="'$(TargetsWindows)' == 'true'" />
25982598
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\LowLevelLifoSemaphore.cs" />
25992599
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\LowLevelLifoSemaphore.Windows.cs" Condition="'$(TargetsWindows)' == 'true'" />
2600-
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\PreAllocatedOverlapped.Windows.cs" Condition="'$(TargetsWindows)' == 'true'"/>
2600+
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\PreAllocatedOverlapped.Windows.cs" Condition="'$(TargetsWindows)' == 'true'" />
26012601
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\PreAllocatedOverlapped.Unix.cs" Condition="'$(TargetsUnix)' == 'true' or '$(TargetsBrowser)' == 'true' or '$(TargetsWasi)' == 'true'" />
26022602
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\PreAllocatedOverlapped.Portable.cs" Condition="('$(TargetsBrowser)' != 'true' and '$(TargetsWasi)' != 'true') or '$(FeatureWasmThreads)' == 'true'" />
2603-
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\RegisteredWaitHandle.Windows.cs" Condition="'$(TargetsWindows)' == 'true'"/>
2604-
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\RegisteredWaitHandle.Unix.cs" Condition="'$(TargetsWindows)' != 'true'"/>
2603+
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\RegisteredWaitHandle.Windows.cs" Condition="'$(TargetsWindows)' == 'true'" />
2604+
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\RegisteredWaitHandle.Unix.cs" Condition="'$(TargetsWindows)' != 'true'" />
26052605
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\RegisteredWaitHandle.Portable.cs" />
26062606
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\LowLevelLifoSemaphoreBase.cs" />
26072607
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\ThreadPoolBoundHandle.Portable.cs" />
@@ -2671,4 +2671,4 @@
26712671
<Compile Include="$(MSBuildThisFileDirectory)System\Numerics\IUnaryPlusOperators.cs" />
26722672
<Compile Include="$(MSBuildThisFileDirectory)System\Numerics\IUnsignedNumber.cs" />
26732673
</ItemGroup>
2674-
</Project>
2674+
</Project>

src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/Marshaling/BaseJSGenerator.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.Runtime.InteropServices.JavaScript;
67
using Microsoft.CodeAnalysis.CSharp;
78
using Microsoft.CodeAnalysis.CSharp.Syntax;
89
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
9-
using System.Runtime.InteropServices.JavaScript;
1010

1111
namespace Microsoft.Interop.JavaScript
1212
{
@@ -26,7 +26,8 @@ protected BaseJSGenerator(MarshalerType marshalerType, IMarshallingGenerator inn
2626
public virtual bool UsesNativeIdentifier(TypePositionInfo info, StubCodeContext context) => _inner.UsesNativeIdentifier(info, context);
2727
public SignatureBehavior GetNativeSignatureBehavior(TypePositionInfo info) => _inner.GetNativeSignatureBehavior(info);
2828
public ValueBoundaryBehavior GetValueBoundaryBehavior(TypePositionInfo info, StubCodeContext context) => _inner.GetValueBoundaryBehavior(info, context);
29-
public ByValueMarshalKindSupport SupportsByValueMarshalKind(ByValueContentsMarshalKind marshalKind, StubCodeContext context) => _inner.SupportsByValueMarshalKind(marshalKind, context);
29+
public ByValueMarshalKindSupport SupportsByValueMarshalKind(ByValueContentsMarshalKind marshalKind, TypePositionInfo info, StubCodeContext context, out GeneratorDiagnostic? diagnostic)
30+
=> _inner.SupportsByValueMarshalKind(marshalKind, info, context, out diagnostic);
3031

3132
public virtual IEnumerable<ExpressionSyntax> GenerateBind(TypePositionInfo info, StubCodeContext context)
3233
{

src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/Marshaling/EmptyJSGenerator.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ internal sealed class EmptyJSGenerator : IJSMarshallingGenerator
1515
public SignatureBehavior GetNativeSignatureBehavior(TypePositionInfo info) => SignatureBehavior.ManagedTypeAndAttributes;
1616
public ValueBoundaryBehavior GetValueBoundaryBehavior(TypePositionInfo info, StubCodeContext context) => ValueBoundaryBehavior.ManagedIdentifier;
1717
public bool IsSupported(TargetFramework target, Version version) => false;
18-
public ByValueMarshalKindSupport SupportsByValueMarshalKind(ByValueContentsMarshalKind marshalKind, StubCodeContext context) => ByValueMarshalKindSupport.NotSupported;
18+
public ByValueMarshalKindSupport SupportsByValueMarshalKind(ByValueContentsMarshalKind marshalKind, TypePositionInfo info, StubCodeContext context, out GeneratorDiagnostic? diagnostic)
19+
=> ByValueMarshalKindSupportDescriptor.Default.GetSupport(marshalKind, info, context, out diagnostic);
1920
public bool UsesNativeIdentifier(TypePositionInfo info, StubCodeContext context) => false;
2021
}
2122
}

src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceGenerator.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<NoWarn>RS2008;RS1038;$(NoWarn)</NoWarn>
1212
<AnalyzerLanguage>cs</AnalyzerLanguage>
1313
<DefineConstants>$(DefineConstants);MICROSOFT_INTEROP_COMINTERFACEGENERATOR</DefineConstants>
14+
<StringResourcesPath>../Common/Resources/Strings.resx</StringResourcesPath>
1415
</PropertyGroup>
1516

1617
<ItemGroup>

src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratorDiagnostics.cs

Lines changed: 49 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -30,38 +30,38 @@ public class Ids
3030

3131
private const string Category = "ComInterfaceGenerator";
3232

33-
/// <inheritdoc cref="SR.RequiresAllowUnsafeBlocksMessage"/>
33+
/// <inheritdoc cref="SR.RequiresAllowUnsafeBlocksMessageCom"/>
3434
public static readonly DiagnosticDescriptor RequiresAllowUnsafeBlocks =
3535
new DiagnosticDescriptor(
3636
Ids.RequiresAllowUnsafeBlocks,
37-
GetResourceString(nameof(SR.RequiresAllowUnsafeBlocksTitle)),
38-
GetResourceString(nameof(SR.RequiresAllowUnsafeBlocksMessage)),
37+
GetResourceString(nameof(SR.RequiresAllowUnsafeBlocksTitleCom)),
38+
GetResourceString(nameof(SR.RequiresAllowUnsafeBlocksMessageCom)),
3939
Category,
4040
DiagnosticSeverity.Error,
4141
isEnabledByDefault: true,
42-
description: GetResourceString(nameof(SR.RequiresAllowUnsafeBlocksDescription)));
42+
description: GetResourceString(nameof(SR.RequiresAllowUnsafeBlocksDescriptionCom)));
4343

44-
/// <inheritdoc cref="SR.InvalidAttributedMethodSignatureMessage"/>
44+
/// <inheritdoc cref="SR.InvalidAttributedMethodSignatureMessageCom"/>
4545
public static readonly DiagnosticDescriptor InvalidAttributedMethodSignature =
4646
new DiagnosticDescriptor(
4747
Ids.InvalidLibraryImportAttributeUsage,
4848
GetResourceString(nameof(SR.InvalidVirtualMethodIndexAttributeUsage)),
49-
GetResourceString(nameof(SR.InvalidAttributedMethodSignatureMessage)),
49+
GetResourceString(nameof(SR.InvalidAttributedMethodSignatureMessageCom)),
5050
Category,
5151
DiagnosticSeverity.Error,
5252
isEnabledByDefault: true,
53-
description: GetResourceString(nameof(SR.InvalidAttributedMethodDescription)));
53+
description: GetResourceString(nameof(SR.InvalidAttributedMethodDescriptionCom)));
5454

55-
/// <inheritdoc cref="SR.InvalidAttributedMethodContainingTypeMissingModifiersMessage"/>
55+
/// <inheritdoc cref="SR.InvalidAttributedMethodContainingTypeMissingModifiersMessageCom"/>
5656
public static readonly DiagnosticDescriptor InvalidAttributedMethodContainingTypeMissingModifiers =
5757
new DiagnosticDescriptor(
5858
Ids.InvalidLibraryImportAttributeUsage,
5959
GetResourceString(nameof(SR.InvalidVirtualMethodIndexAttributeUsage)),
60-
GetResourceString(nameof(SR.InvalidAttributedMethodContainingTypeMissingModifiersMessage)),
60+
GetResourceString(nameof(SR.InvalidAttributedMethodContainingTypeMissingModifiersMessageCom)),
6161
Category,
6262
DiagnosticSeverity.Error,
6363
isEnabledByDefault: true,
64-
description: GetResourceString(nameof(SR.InvalidAttributedMethodDescription)));
64+
description: GetResourceString(nameof(SR.InvalidAttributedMethodDescriptionCom)));
6565

6666
/// <inheritdoc cref="SR.InvalidGeneratedComInterfaceUsageMissingPartialModifier"/>
6767
public static readonly DiagnosticDescriptor InvalidAttributedInterfaceMissingPartialModifiers =
@@ -83,7 +83,7 @@ public class Ids
8383
Category,
8484
DiagnosticSeverity.Error,
8585
isEnabledByDefault: true,
86-
description: GetResourceString(nameof(SR.InvalidAttributedMethodDescription)));
86+
description: GetResourceString(nameof(SR.InvalidAttributedMethodDescriptionCom)));
8787

8888
/// <inheritdoc cref="SR.InvalidStringMarshallingConfigurationOnInterfaceMessage"/>
8989
public static readonly DiagnosticDescriptor InvalidStringMarshallingMismatchBetweenBaseAndDerived =
@@ -150,27 +150,27 @@ public class Ids
150150
isEnabledByDefault: true,
151151
description: GetResourceString(nameof(SR.InvalidExceptionMarshallingConfigurationDescription)));
152152

153-
/// <inheritdoc cref="SR.InvalidExceptionMarshallingConfigurationMessage"/>
153+
/// <inheritdoc cref="SR.TypeNotSupportedMessageParameterCom"/>
154154
public static readonly DiagnosticDescriptor ParameterTypeNotSupported =
155155
new DiagnosticDescriptor(
156156
Ids.TypeNotSupported,
157157
GetResourceString(nameof(SR.TypeNotSupportedTitle)),
158-
GetResourceString(nameof(SR.TypeNotSupportedMessageParameter)),
158+
GetResourceString(nameof(SR.TypeNotSupportedMessageParameterCom)),
159159
Category,
160160
DiagnosticSeverity.Error,
161161
isEnabledByDefault: true,
162-
description: GetResourceString(nameof(SR.TypeNotSupportedDescription)));
162+
description: GetResourceString(nameof(SR.TypeNotSupportedDescriptionCom)));
163163

164-
/// <inheritdoc cref="SR.TypeNotSupportedMessageReturn"/>
164+
/// <inheritdoc cref="SR.TypeNotSupportedMessageReturnCom"/>
165165
public static readonly DiagnosticDescriptor ReturnTypeNotSupported =
166166
new DiagnosticDescriptor(
167167
Ids.TypeNotSupported,
168168
GetResourceString(nameof(SR.TypeNotSupportedTitle)),
169-
GetResourceString(nameof(SR.TypeNotSupportedMessageReturn)),
169+
GetResourceString(nameof(SR.TypeNotSupportedMessageReturnCom)),
170170
Category,
171171
DiagnosticSeverity.Error,
172172
isEnabledByDefault: true,
173-
description: GetResourceString(nameof(SR.TypeNotSupportedDescription)));
173+
description: GetResourceString(nameof(SR.TypeNotSupportedDescriptionCom)));
174174

175175
/// <inheritdoc cref="SR.TypeNotSupportedMessageParameterWithDetails"/>
176176
public static readonly DiagnosticDescriptor ParameterTypeNotSupportedWithDetails =
@@ -181,7 +181,7 @@ public class Ids
181181
Category,
182182
DiagnosticSeverity.Error,
183183
isEnabledByDefault: true,
184-
description: GetResourceString(nameof(SR.TypeNotSupportedDescription)));
184+
description: GetResourceString(nameof(SR.TypeNotSupportedDescriptionCom)));
185185

186186
/// <inheritdoc cref="SR.TypeNotSupportedMessageReturnWithDetails"/>
187187
public static readonly DiagnosticDescriptor ReturnTypeNotSupportedWithDetails =
@@ -192,84 +192,84 @@ public class Ids
192192
Category,
193193
DiagnosticSeverity.Error,
194194
isEnabledByDefault: true,
195-
description: GetResourceString(nameof(SR.TypeNotSupportedDescription)));
195+
description: GetResourceString(nameof(SR.TypeNotSupportedDescriptionCom)));
196196

197-
/// <inheritdoc cref="SR.ConfigurationNotSupportedMessageParameter"/>
197+
/// <inheritdoc cref="SR.ConfigurationNotSupportedMessageParameterCom"/>
198198
public static readonly DiagnosticDescriptor ParameterConfigurationNotSupported =
199199
new DiagnosticDescriptor(
200200
Ids.ConfigurationNotSupported,
201-
GetResourceString(nameof(SR.ConfigurationNotSupportedTitle)),
202-
GetResourceString(nameof(SR.ConfigurationNotSupportedMessageParameter)),
201+
GetResourceString(nameof(SR.ConfigurationNotSupportedTitleCom)),
202+
GetResourceString(nameof(SR.ConfigurationNotSupportedMessageParameterCom)),
203203
Category,
204204
DiagnosticSeverity.Error,
205205
isEnabledByDefault: true,
206-
description: GetResourceString(nameof(SR.ConfigurationNotSupportedDescription)));
206+
description: GetResourceString(nameof(SR.ConfigurationNotSupportedDescriptionCom)));
207207

208-
/// <inheritdoc cref="SR.ConfigurationNotSupportedMessageReturn"/>
208+
/// <inheritdoc cref="SR.ConfigurationNotSupportedMessageReturnCom"/>
209209
public static readonly DiagnosticDescriptor ReturnConfigurationNotSupported =
210210
new DiagnosticDescriptor(
211211
Ids.ConfigurationNotSupported,
212-
GetResourceString(nameof(SR.ConfigurationNotSupportedTitle)),
213-
GetResourceString(nameof(SR.ConfigurationNotSupportedMessageReturn)),
212+
GetResourceString(nameof(SR.ConfigurationNotSupportedTitleCom)),
213+
GetResourceString(nameof(SR.ConfigurationNotSupportedMessageReturnCom)),
214214
Category,
215215
DiagnosticSeverity.Error,
216216
isEnabledByDefault: true,
217-
description: GetResourceString(nameof(SR.ConfigurationNotSupportedDescription)));
217+
description: GetResourceString(nameof(SR.ConfigurationNotSupportedDescriptionCom)));
218218

219-
/// <inheritdoc cref="SR.MarshalAsConfigurationNotSupportedMessageParameter"/>
219+
/// <inheritdoc cref="SR.MarshalAsConfigurationNotSupportedMessageParameterCom"/>
220220
public static readonly DiagnosticDescriptor MarshalAsParameterConfigurationNotSupported =
221221
new DiagnosticDescriptor(
222222
GeneratorDiagnostics.Ids.ConfigurationNotSupported,
223-
GetResourceString(nameof(SR.ConfigurationNotSupportedTitle)),
224-
GetResourceString(nameof(SR.MarshalAsConfigurationNotSupportedMessageParameter)),
223+
GetResourceString(nameof(SR.ConfigurationNotSupportedTitleCom)),
224+
GetResourceString(nameof(SR.MarshalAsConfigurationNotSupportedMessageParameterCom)),
225225
Category,
226226
DiagnosticSeverity.Error,
227227
isEnabledByDefault: true,
228-
description: GetResourceString(nameof(SR.ConfigurationNotSupportedDescription)));
228+
description: GetResourceString(nameof(SR.ConfigurationNotSupportedDescriptionCom)));
229229

230-
/// <inheritdoc cref="SR.MarshalAsConfigurationNotSupportedMessageReturn"/>
230+
/// <inheritdoc cref="SR.MarshalAsConfigurationNotSupportedMessageReturnCom"/>
231231
public static readonly DiagnosticDescriptor MarshalAsReturnConfigurationNotSupported =
232232
new DiagnosticDescriptor(
233233
GeneratorDiagnostics.Ids.ConfigurationNotSupported,
234-
GetResourceString(nameof(SR.ConfigurationNotSupportedTitle)),
235-
GetResourceString(nameof(SR.MarshalAsConfigurationNotSupportedMessageReturn)),
234+
GetResourceString(nameof(SR.ConfigurationNotSupportedTitleCom)),
235+
GetResourceString(nameof(SR.MarshalAsConfigurationNotSupportedMessageReturnCom)),
236236
Category,
237237
DiagnosticSeverity.Error,
238238
isEnabledByDefault: true,
239-
description: GetResourceString(nameof(SR.ConfigurationNotSupportedDescription)));
239+
description: GetResourceString(nameof(SR.ConfigurationNotSupportedDescriptionCom)));
240240

241-
/// <inheritdoc cref="SR.ConfigurationNotSupportedMessage"/>
241+
/// <inheritdoc cref="SR.ConfigurationNotSupportedMessageCom"/>
242242
public static readonly DiagnosticDescriptor ConfigurationNotSupported =
243243
new DiagnosticDescriptor(
244244
Ids.ConfigurationNotSupported,
245-
GetResourceString(nameof(SR.ConfigurationNotSupportedTitle)),
246-
GetResourceString(nameof(SR.ConfigurationNotSupportedMessage)),
245+
GetResourceString(nameof(SR.ConfigurationNotSupportedTitleCom)),
246+
GetResourceString(nameof(SR.ConfigurationNotSupportedMessageCom)),
247247
Category,
248248
DiagnosticSeverity.Error,
249249
isEnabledByDefault: true,
250-
description: GetResourceString(nameof(SR.ConfigurationNotSupportedDescription)));
250+
description: GetResourceString(nameof(SR.ConfigurationNotSupportedDescriptionCom)));
251251

252-
/// <inheritdoc cref="SR.ConfigurationNotSupportedMessageValue"/>
252+
/// <inheritdoc cref="SR.ConfigurationNotSupportedMessageValueCom"/>
253253
public static readonly DiagnosticDescriptor ConfigurationValueNotSupported =
254254
new DiagnosticDescriptor(
255255
Ids.ConfigurationNotSupported,
256-
GetResourceString(nameof(SR.ConfigurationNotSupportedTitle)),
257-
GetResourceString(nameof(SR.ConfigurationNotSupportedMessageValue)),
256+
GetResourceString(nameof(SR.ConfigurationNotSupportedTitleCom)),
257+
GetResourceString(nameof(SR.ConfigurationNotSupportedMessageValueCom)),
258258
Category,
259259
DiagnosticSeverity.Error,
260260
isEnabledByDefault: true,
261-
description: GetResourceString(nameof(SR.ConfigurationNotSupportedDescription)));
261+
description: GetResourceString(nameof(SR.ConfigurationNotSupportedDescriptionCom)));
262262

263-
/// <inheritdoc cref="SR.ConfigurationNotSupportedMessageMarshallingInfo"/>
263+
/// <inheritdoc cref="SR.ConfigurationNotSupportedMessageMarshallingInfoCom"/>
264264
public static readonly DiagnosticDescriptor MarshallingAttributeConfigurationNotSupported =
265265
new DiagnosticDescriptor(
266266
Ids.ConfigurationNotSupported,
267-
GetResourceString(nameof(SR.ConfigurationNotSupportedTitle)),
268-
GetResourceString(nameof(SR.ConfigurationNotSupportedMessageMarshallingInfo)),
267+
GetResourceString(nameof(SR.ConfigurationNotSupportedTitleCom)),
268+
GetResourceString(nameof(SR.ConfigurationNotSupportedMessageMarshallingInfoCom)),
269269
Category,
270270
DiagnosticSeverity.Error,
271271
isEnabledByDefault: true,
272-
description: GetResourceString(nameof(SR.ConfigurationNotSupportedDescription)));
272+
description: GetResourceString(nameof(SR.ConfigurationNotSupportedDescriptionCom)));
273273

274274
/// <inheritdoc cref="SR.MethodNotDeclaredInAttributedInterfaceMessage"/>
275275
public static readonly DiagnosticDescriptor MethodNotDeclaredInAttributedInterface =
@@ -414,6 +414,7 @@ public class Ids
414414
isEnabledByDefault: true,
415415
description: GetResourceString(nameof(SR.ClassDoesNotImplementAnyGeneratedComInterfacesDescription)));
416416

417+
/// <inheritdoc cref="SR.UnnecessaryParameterMarshallingInfoMessage"/>
417418
public static readonly DiagnosticDescriptor UnnecessaryParameterMarshallingInfo =
418419
new DiagnosticDescriptor(
419420
Ids.UnnecessaryMarshallingInfo,
@@ -428,6 +429,7 @@ public class Ids
428429
WellKnownDiagnosticTags.Unnecessary
429430
});
430431

432+
/// <inheritdoc cref="SR.UnnecessaryReturnMarshallingInfoMessage"/>
431433
public static readonly DiagnosticDescriptor UnnecessaryReturnMarshallingInfo =
432434
new DiagnosticDescriptor(
433435
Ids.UnnecessaryMarshallingInfo,

0 commit comments

Comments
 (0)