Skip to content

Commit

Permalink
Fix typo in ComInterfaceInfo.OptionsAreValid (#102384)
Browse files Browse the repository at this point in the history
We want to check the derived type has the same wrapper as the base type.
But the code seems to have a copy-paste or typo error where it checks
the derived type wrapper against a different base type wrapper.
  • Loading branch information
omajid authored Jul 1, 2024
1 parent 6e4e7c3 commit 426b00c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ private static bool OptionsAreValid(
var baseAttr = GeneratedComInterfaceData.From(baseAttrInfo);
// The base type must specify at least the same wrappers as the derived type.
if ((attrInfo.Options.HasFlag(ComInterfaceOptions.ManagedObjectWrapper) && !baseAttr.Options.HasFlag(ComInterfaceOptions.ManagedObjectWrapper))
|| (attrInfo.Options.HasFlag(ComInterfaceOptions.ManagedObjectWrapper) && !baseAttr.Options.HasFlag(ComInterfaceOptions.ComObjectWrapper)))
|| (attrInfo.Options.HasFlag(ComInterfaceOptions.ComObjectWrapper) && !baseAttr.Options.HasFlag(ComInterfaceOptions.ComObjectWrapper)))
{
optionsDiagnostic = DiagnosticInfo.Create(
GeneratorDiagnostics.InvalidOptionsOnInterface,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,27 @@ partial interface IComInterface2 : IComInterface
void Method2();
}
""";

public string DerivedComInterfaceTypeMismatchInWrappers => $$"""
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;
[GeneratedComInterface(Options = ComInterfaceOptions.ComObjectWrapper)]
[Guid("0E7204B5-4B61-4E06-B872-82BA652F2ECA")]
partial interface IComInterface
{
void Method();
}
[GeneratedComInterface(Options = ComInterfaceOptions.ManagedObjectWrapper)]
[Guid("0E7204B5-4B61-4E06-B872-82BA652F2ECA")]
partial interface {|#0:IComInterface2|} : IComInterface
{
void Method2();
}
""";

public string DerivedComInterfaceTypeMultipleComInterfaceBases => $$"""
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ public static IEnumerable<object[]> ComInterfaceGeneratorSnippetsToCompile()
.WithLocation(1)
.WithArguments("Event", "INativeAPI"),
} };

yield return new object[] { ID(), codeSnippets.DerivedComInterfaceTypeMismatchInWrappers, new[]
{
VerifyComInterfaceGenerator.Diagnostic(GeneratorDiagnostics.InvalidOptionsOnInterface)
.WithLocation(0)
.WithArguments("IComInterface2", SR.BaseInterfaceMustGenerateAtLeastSameWrappers),
} };
}

[Theory]
Expand Down

0 comments on commit 426b00c

Please sign in to comment.