Skip to content

CA1416 when property accessor is unsupported on Mac Catalyst #7633

Open
@rolfbjarne

Description

@rolfbjarne

Analyzer

Diagnostic ID: warning CA1416: This call site is reachable on: 'ios', 'maccatalyst'. 'TestType.GetSomething.get' is supported on: 'ios'.

Analyzer source

SDK: Built-in CA analyzers in .NET 5 SDK or later

$ dotnet --version
9.0.200

Describe the bug

Steps To Reproduce

Class library with:

using System.Runtime.Versioning;

[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("ios")]
partial class TestType {
    [UnsupportedOSPlatform ("maccatalyst")]
    [SupportedOSPlatform ("ios")]
    void DoSomething ()
    {
        Console.WriteLine (GetSomething);
    }

    [UnsupportedOSPlatform ("maccatalyst")]
    [SupportedOSPlatform ("ios")]
    public static object GetSomething {
        [UnsupportedOSPlatform ("maccatalyst")]
        [SupportedOSPlatform ("ios")]
        get {
            return "";
        }
    }
}

shows this (on the Console.WriteLine line):

warning CA1416: This call site is reachable on: 'ios', 'maccatalyst'. 'TestType.GetSomething.get' is supported on: 'ios'.

Binlog: msbuild.binlog.zip

Test project: ioslibrary-4c6c0b2.zip

Unit test: rolfbjarne@e3ef16a

Unit test results show:

Microsoft.NetCore.Analyzers.InteropServices.UnitTests.PlatformCompatabilityAnalyzerTests.UnsupportedMacCatalystPropertyAccessor​9ms
Error:
System.InvalidOperationException : Context: Diagnostics of test state
Mismatch between number of diagnostics returned, expected "0" actual "1"

Diagnostics:
// /0/Test0.cs(12,28): warning CA1416: This call site is reachable on: 'ios', 'maccatalyst'. 'TestType.GetSomething.get' is supported on: 'ios'.
VerifyCS.Diagnostic(PlatformCompatibilityAnalyzer.CA1416).WithSpan(12, 28, 12, 40).WithArguments("TestType.GetSomething.get", "'ios'", "'ios', 'maccatalyst'"),


Stack trace:
   at Microsoft.CodeAnalysis.Testing.DefaultVerifier.Equal[T](T expected, T actual, String message) in /_/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/DefaultVerifier.cs:line 79
   at Microsoft.CodeAnalysis.Testing.AnalyzerTest`1.VerifyDiagnosticResults(IEnumerable`1 actualResults, ImmutableArray`1 analyzers, DiagnosticResult[] expectedResults, IVerifier verifier) in /_/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/AnalyzerTest`1.cs:line 546
   at Microsoft.CodeAnalysis.Testing.AnalyzerTest`1.VerifyDiagnosticsAsync(EvaluatedProjectState primaryProject, ImmutableArray`1 additionalProjects, DiagnosticResult[] expected, IVerifier verifier, CancellationToken cancellationToken) in /_/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/AnalyzerTest`1.cs:line 449
   at Microsoft.CodeAnalysis.Testing.CodeFixTest`1.RunImplAsync(CancellationToken cancellationToken) in /_/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.CodeFix.Testing/CodeFixTest`1.cs:line 311
   at Microsoft.CodeAnalysis.Testing.AnalyzerTest`1.RunAsync(CancellationToken cancellationToken) in /_/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/AnalyzerTest`1.cs:line 172
   at Microsoft.NetCore.Analyzers.InteropServices.UnitTests.PlatformCompatabilityAnalyzerTests.VerifyAnalyzerCSAsync(String sourceCode, String editorconfigText) in /Users/rolf/work/dotnet/roslyn-analyzers/src/NetAnalyzers/UnitTests/Microsoft.NetCore.Analyzers/InteropServices/PlatformCompatibilityAnalyzerTests.cs:line 4233
   at Microsoft.NetCore.Analyzers.InteropServices.UnitTests.PlatformCompatabilityAnalyzerTests.UnsupportedMacCatalystPropertyAccessor() in /Users/rolf/work/dotnet/roslyn-analyzers/src/NetAnalyzers/UnitTests/Microsoft.NetCore.Analyzers/InteropServices/PlatformCompatibilityAnalyzerTests.cs:line 4189
--- End of stack trace from previous location ---

Expected behavior

No warning

Actual behavior

CA1416 as described above

Additional context

This is not fixed by #7569.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions