Skip to content

Commit

Permalink
[release/8.0-preview5] Use fully qualified type names for parameters …
Browse files Browse the repository at this point in the history
…and don't copy parameter attributes (#86899)

* Use fully qualified type names for parameters and don't copy parameter attributes

The issue dotnet/source-build#3483 looks similar to the issues I found before fixing in #86731. The relevant changes were in ComMethodContext.cs. If it's the same issue I was hitting, the attribute syntax was being copied over without adding 'using' statements or changing the attribute name to be fully qualified. I haven't validated yet, but this should fix it by just not copying the attributes for the parameters since they're not strictly necessary.

* Add test for change
  • Loading branch information
jtschuster authored May 30, 2023
1 parent 90c32f6 commit bc78804
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ private MethodDeclarationSyntax CreateUnreachableExceptionStub()
.WithAttributeLists(List<AttributeListSyntax>())
.WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier(
ParseName(OriginalDeclaringInterface.Info.Type.FullTypeName)))
.WithParameterList(ParameterList(SeparatedList(GenerationContext.SignatureContext.StubParameters)))
.WithExpressionBody(ArrowExpressionClause(
ThrowExpression(
ObjectCreationExpression(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,24 @@ partial interface IComInterface2
}
""";

public string ComInterfaceInheritanceWithParametersWithAttributes => $$"""
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;

{{GeneratedComInterface}}
partial interface IComInterface
{
void Method([MarshalUsing(typeof(Utf8StringMarshaller))] string myString);
}
{{GeneratedComInterface}}
partial interface IComInterface1 : IComInterface
{
void Method2([MarshalUsing(typeof(Utf8StringMarshaller))] string myString);
}
""";
public class ManagedToUnmanaged : IVirtualMethodIndexSignatureProvider
{
public MarshalDirection Direction => MarshalDirection.ManagedToUnmanaged;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ public static IEnumerable<object[]> ComInterfaceSnippetsToCompile()
CodeSnippets codeSnippets = new(new GeneratedComInterfaceAttributeProvider());
yield return new object[] { ID(), codeSnippets.DerivedComInterfaceType };
yield return new object[] { ID(), codeSnippets.ComInterfaceParameters };
yield return new object[] { ID(), codeSnippets.ComInterfaceInheritanceWithParametersWithAttributes };
}

[Theory]
Expand Down

0 comments on commit bc78804

Please sign in to comment.