Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected CA1416 with multiple SupportedOSPlatformGuard attributes #7530

Open
rolfbjarne opened this issue Jan 14, 2025 · 0 comments
Open

Comments

@rolfbjarne
Copy link
Member

Analyzer

Diagnostic ID: CA1416: This call site is reachable on: 'macOS/OSX' 15.0 and later, 'tvos' 12.2 and later. 'Other.DoSomething()' is only supported on: 'tvos' 15.0 and later.

Analyzer source

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

Version: SDK 9.0.100

Describe the bug

Incorrect CA1416 is reported when there are more than one SupportedOSPlatformGuard on a member.

Steps To Reproduce

Test project:

allplatformlib-ea082d2.zip

Binlog:

msbuild.binlog.zip

This is the code:

using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.Versioning;

class C {
	[SupportedOSPlatform ("tvos15.0")]
	[SupportedOSPlatform ("macos15.0")]
	public static void DoSomething ()
	{
	}

    [SupportedOSPlatform ("macos15.0")]
    [SupportedOSPlatform ("tvos12.2")]
    static void GetFilter (string filterName)
    {
        if (IsAtLeast) {
			DoSomething ();
        }
    }

    [SupportedOSPlatformGuard ("macos15.0")]
    [SupportedOSPlatformGuard ("tvos15.0")]
	static bool IsAtLeast = true;
}

This reports:

warning CA1416: This call site is reachable on: 'macOS/OSX' 15.0 and later, 'tvos' 12.2 and later. 'C.DoSomething()' is only supported on: 'tvos' 15.0 and later. (

Which is incorrect, because the call site is not reachable on tvos12.2 or later (due to the SupportedOSPlatformGuard attribute on IsAtLeast).

Removing either of the macos or tvos availability attributes on all members fixes the warning.

Expected behavior

No warning.

Actual behavior

warning CA1416: This call site is reachable on: 'macOS/OSX' 15.0 and later, 'tvos' 12.2 and later. 'C.DoSomething()' is only supported on: 'tvos' 15.0 and later. (

Additional context

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant