From 9945a79cfaab46b353a6c71447938137e354a88d Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Wed, 19 Jul 2023 16:48:31 -0700 Subject: [PATCH 1/3] Fix issue references in ConvertToLibraryImportAnalyzerTests Add a directed test for function pointers and remove an outdated ActiveIssue --- .../ConvertToLibraryImportAnalyzerTests.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/ConvertToLibraryImportAnalyzerTests.cs b/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/ConvertToLibraryImportAnalyzerTests.cs index 8e8470e08805b..b8de2216dac6b 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/ConvertToLibraryImportAnalyzerTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/ConvertToLibraryImportAnalyzerTests.cs @@ -34,8 +34,6 @@ public static IEnumerable NoMarshallingRequiredTypes() => new[] new object[] { typeof(int*) }, new object[] { typeof(bool*) }, new object[] { typeof(char*) }, - // See issue https://github.com/dotnet/runtime/issues/71891 - // new object[] { typeof(delegate* ) }, new object[] { typeof(IntPtr) }, new object[] { typeof(ConsoleKey) }, // enum }; @@ -50,7 +48,6 @@ public static IEnumerable UnsupportedTypes() => new[] [Theory] [MemberData(nameof(MarshallingRequiredTypes))] [MemberData(nameof(NoMarshallingRequiredTypes))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/60909", typeof(PlatformDetection), nameof(PlatformDetection.IsArm64Process), nameof(PlatformDetection.IsWindows))] public async Task TypeRequiresMarshalling_ReportsDiagnostic(Type type) { string source = DllImportWithType(type.FullName!); @@ -64,6 +61,20 @@ await VerifyCS.VerifyAnalyzerAsync( .WithArguments("Method_Return")); } + [Fact] + public async Task FunctionPointer_ReportsDiagnostic(Type type) + { + string source = "delegate* unmanaged"; + await VerifyCS.VerifyAnalyzerAsync( + source, + VerifyCS.Diagnostic(ConvertToLibraryImport) + .WithLocation(0) + .WithArguments("Method_Parameter"), + VerifyCS.Diagnostic(ConvertToLibraryImport) + .WithLocation(1) + .WithArguments("Method_Return")); + } + [Theory] [MemberData(nameof(MarshallingRequiredTypes))] [MemberData(nameof(NoMarshallingRequiredTypes))] From 78fac4689529342d037438cab444eb5d6b32a427 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Thu, 20 Jul 2023 11:00:04 -0700 Subject: [PATCH 2/3] Remove unnecessary parameter. --- .../ConvertToLibraryImportAnalyzerTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/ConvertToLibraryImportAnalyzerTests.cs b/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/ConvertToLibraryImportAnalyzerTests.cs index b8de2216dac6b..6d2fadf3cb671 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/ConvertToLibraryImportAnalyzerTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/ConvertToLibraryImportAnalyzerTests.cs @@ -62,7 +62,7 @@ await VerifyCS.VerifyAnalyzerAsync( } [Fact] - public async Task FunctionPointer_ReportsDiagnostic(Type type) + public async Task FunctionPointer_ReportsDiagnostic() { string source = "delegate* unmanaged"; await VerifyCS.VerifyAnalyzerAsync( From 015f3ca72049167bf7e45e82c44e634f6bb67228 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Tue, 25 Jul 2023 13:28:06 -0700 Subject: [PATCH 3/3] Update src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/ConvertToLibraryImportAnalyzerTests.cs --- .../ConvertToLibraryImportAnalyzerTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/ConvertToLibraryImportAnalyzerTests.cs b/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/ConvertToLibraryImportAnalyzerTests.cs index 6d2fadf3cb671..376f604439c23 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/ConvertToLibraryImportAnalyzerTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/ConvertToLibraryImportAnalyzerTests.cs @@ -64,7 +64,7 @@ await VerifyCS.VerifyAnalyzerAsync( [Fact] public async Task FunctionPointer_ReportsDiagnostic() { - string source = "delegate* unmanaged"; + string source = DllImportWithType("delegate* unmanaged"); await VerifyCS.VerifyAnalyzerAsync( source, VerifyCS.Diagnostic(ConvertToLibraryImport)