Skip to content

Support UIDevice.CheckSystemVersion from Microsoft.iOS/Catalyst workloads or provide SupportedOSPlatformGuard/UnsupportedOSPlatformGuard that supports dynamic versions #6204

@chamons

Description

@chamons

Analyzer

Diagnostic ID: CA1416

Analyzer source

NuGet Package: Microsoft.CodeAnalysis.NetAnalyzers

Version: 7.0.0-preview1.22403.2

Describe the bug

CA1416 is incorrectly determining call site reachability as it does not understand that UIDevice.CheckSystemVersion is excluding them.

The supported extension mechanism SupportedOSPlatformGuard/UnsupportedOSPlatformGuard does not allow dynamic versions, so we can not fix this on our end.

As an example:

UIDevice.CurrentDevice.CheckSystemVersion(13, 0) would imply [SupportedOSPlatformGuard("ios13.0")] but

UIDevice.CurrentDevice.CheckSystemVersion(14, 0) would imply [SupportedOSPlatformGuard("ios14.0")] instead.

The Windows API IsWindowsVersionAtLeast does not use attributes at all but I'm told is hard coded in the analyzer directly.

Please either hard code UIDevice.CheckSystemVersion or extend SupportedOSPlatformGuard/UnsupportedOSPlatformGuard to support arguments.

Steps To Reproduce

An example of this behavior can be seen in #6189

Additional context

Originally #6189 and then dotnet/macios#16250

Discussed with @buyaa-n offline prior to filing.

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