Skip to content

Unexpected CA1416 with multiple SupportedOSPlatformGuard attributes #7530

@rolfbjarne

Description

@rolfbjarne

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

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