Skip to content

LibraryImportGenerator ConvertToLibraryImportAnalyzerTests failing with new function pointer support #71891

@steveharter

Description

@steveharter

Please investigate cause of test failure related to function pointers from #69273,

The file src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/ConvertToLibraryImportAnalyzerTests.cs has this test that is failing for a function pointer. The line with the function pointer has been commented out (instead of disabling the whole test).

    public class ConvertToLibraryImportAnalyzerTests
    {
...
        public static IEnumerable<object[]> NoMarshallingRequiredTypes() => new[]
        {
            new object[] { typeof(byte) },
            new object[] { typeof(int) },
            new object[] { typeof(byte*) },
            new object[] { typeof(int*) },
            new object[] { typeof(bool*) },
            new object[] { typeof(char*) },
>>          new object[] { typeof(delegate* <void>) },
            new object[] { typeof(IntPtr) },
            new object[] { typeof(ConsoleKey) }, // enum
        };

new object[] { typeof(delegate* ) },

 Discovering: LibraryImportGenerator.Unit.Tests (method display = ClassAndMethod, method display options = None)
  Discovered:  LibraryImportGenerator.Unit.Tests (found 122 of 127 test cases)
  Starting:    LibraryImportGenerator.Unit.Tests (parallel test collections = on, max threads = 2)
    LibraryImportGenerator.UnitTests.Compiles.ValidateSnippetsWithMarshalType [SKIP]
      No current scenarios to test.
    LibraryImportGenerator.UnitTests.ConvertToLibraryImportAnalyzerTests.ByRef_ReportsDiagnostic(type: typeof(*())) [FAIL]
      Microsoft.CodeAnalysis.Testing.Verifiers.EqualWithMessageException : Context: Diagnostics of test state
      Mismatch between number of diagnostics returned, expected "3" actual "9"
      
      Diagnostics:
      // /0/Test0.cs(6,31): info SYSLIB1054: Mark the method 'Method_In' with 'LibraryImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
      VerifyCS.Diagnostic().WithSpan(6, 31, 6, 40).WithArguments("Method_In"),
      // /0/Test0.cs(6,45): error CS0246: The type or namespace name 'p' could not be found (are you missing a using directive or an assembly reference?)
      DiagnosticResult.CompilerError("CS0246").WithSpan(6, 45, 6, 46).WithArguments("p"),
      // /0/Test0.cs(6,46): error CS1001: Identifier expected
      DiagnosticResult.CompilerError("CS1001").WithSpan(6, 46, 6, 47),
      // /0/Test0.cs(9,31): info SYSLIB1054: Mark the method 'Method_Out' with 'LibraryImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
      VerifyCS.Diagnostic().WithSpan(9, 31, 9, 41).WithArguments("Method_Out"),
      // /0/Test0.cs(9,47): error CS0246: The type or namespace name 'p' could not be found (are you missing a using directive or an assembly reference?)
      DiagnosticResult.CompilerError("CS0246").WithSpan(9, 47, 9, 48).WithArguments("p"),
      // /0/Test0.cs(9,48): error CS1001: Identifier expected
      DiagnosticResult.CompilerError("CS1001").WithSpan(9, 48, 9, 49),
      // /0/Test0.cs(12,31): info SYSLIB1054: Mark the method 'Method_Ref' with 'LibraryImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
      VerifyCS.Diagnostic().WithSpan(12, 31, 12, 41).WithArguments("Method_Ref"),
      // /0/Test0.cs(12,47): error CS0246: The type or namespace name 'p' could not be found (are you missing a using directive or an assembly reference?)
      DiagnosticResult.CompilerError("CS0246").WithSpan(12, 47, 12, 48).WithArguments("p"),
      // /0/Test0.cs(12,48): error CS1001: Identifier expected
      DiagnosticResult.CompilerError("CS1001").WithSpan(12, 48, 12, 49),
      
      
      Assert.Equal() Failure
      Expected: 3
      Actual:   9
      Stack Trace:
        /_/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Testing.Verifiers.XUnit/XUnitVerifier.cs(49,0): at Microsoft.CodeAnalysis.Testing.Verifiers.XUnitVerifier.Equal[T](T expected, T actual, String message)
        /_/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/AnalyzerTest`1.cs(361,0): at Microsoft.CodeAnalysis.Testing.AnalyzerTest`1.VerifyDiagnosticResults(IEnumerable`1 actualResults, ImmutableArray`1 analyzers, DiagnosticResult[] expectedResults, IVerifier verifier)
        /_/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/AnalyzerTest`1.cs(274,0): at Microsoft.CodeAnalysis.Testing.AnalyzerTest`1.VerifyDiagnosticsAsync(EvaluatedProjectState primaryProject, ImmutableArray`1 additionalProjects, DiagnosticResult[] expected, IVerifier verifier, CancellationToken cancellationToken)
        /_/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.CodeFix.Testing/CodeFixTest`1.cs(304,0): at Microsoft.CodeAnalysis.Testing.CodeFixTest`1.RunImplAsync(CancellationToken cancellationToken)
        /_/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/AnalyzerTest`1.cs(182,0): at Microsoft.CodeAnalysis.Testing.AnalyzerTest`1.RunAsync(CancellationToken cancellationToken)
        /_/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/Verifiers/CSharpAnalyzerVerifier.cs(37,0): at LibraryImportGenerator.UnitTests.Verifiers.CSharpAnalyzerVerifier`1.VerifyAnalyzerAsync(String source, DiagnosticResult[] expected)
        /_/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/ConvertToLibraryImportAnalyzerTests.cs(87,0): at LibraryImportGenerator.UnitTests.ConvertToLibraryImportAnalyzerTests.ByRef_ReportsDiagnostic(Type type)
        --- End of stack trace from previous location ---
      Microsoft.CodeAnalysis.Testing.Verifiers.EqualWithMessageException : Context: Diagnostics of test state
      Mismatch between number of diagnostics returned, expected "2" actual "6"
      
      Diagnostics:
      // /0/Test0.cs(6,31): info SYSLIB1054: Mark the method 'Method_Parameter' with 'LibraryImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
      VerifyCS.Diagnostic().WithSpan(6, 31, 6, 47).WithArguments("Method_Parameter"),
      // /0/Test0.cs(6,49): error CS0246: The type or namespace name 'p' could not be found (are you missing a using directive or an assembly reference?)
      DiagnosticResult.CompilerError("CS0246").WithSpan(6, 49, 6, 50).WithArguments("p"),
      // /0/Test0.cs(6,50): error CS1001: Identifier expected
      DiagnosticResult.CompilerError("CS1001").WithSpan(6, 50, 6, 51),
      // /0/Test0.cs(8,6): error CS0592: Attribute 'DllImport' is not valid on this declaration type. It is only valid on 'method' declarations.
      DiagnosticResult.CompilerError("CS0592").WithSpan(8, 6, 8, 15).WithArguments("DllImport", "method"),
      // /0/Test0.cs(9,27): error CS0107: More than one protection modifier
      DiagnosticResult.CompilerError("CS0107").WithSpan(9, 27, 9, 40),
      // /0/Test0.cs(9,27): error CS1520: Method must have a return type
      DiagnosticResult.CompilerError("CS1520").WithSpan(9, 27, 9, 40),

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions