dotnet / roslyn-analyzers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CA1416 about API not being available on Mac Catalyst when it is

rolfbjarne opened this issue · comments

Analyzer

Diagnostic ID: CA1416: This call site is reachable on: 'iOS' 13.0 and later, 'maccatalyst' 15.0 and later. 'AppDelegate.DoSomething()' is only supported on: 'ios' 14.0 and later.

Describe the bug

An API decorated with [SupportedOSPlatform("maccatalyst")] (no version) doesn't seem to be detected as supported on Mac Catalyst.

Steps To Reproduce

  1. Create a new iOS project (dotnet new ios).
  2. Set SupportedOSPlatformVersion=13.0 in the csproj.
  3. Add the following code to it (for instance in the AppDelegate class / in AppDelegate.cs):
private void Tapped()
{
	if (OperatingSystem.IsIOSVersionAtLeast(15,0))
		DoSomething ();
}

[SupportedOSPlatform ("ios14.0")]
[SupportedOSPlatform ("maccatalyst")]
public void DoSomething () {}

Complete test project (+ binlog):
ios-plain-52d66f2.zip

Expected behavior

No warning.

Actual behavior

warning CA1416: This call site is reachable on: 'iOS' 13.0 and later, 'maccatalyst' 15.0 and later. 'AppDelegate.DoSomething()' is only supported on: 'ios' 14.0 and later.

Note that the warning message is wrong on more than one account:

  1. The call site is reachable on iOS 15.0 (not 13.0).
  2. The called API is (correctly) supported on iOS 14+, but also on all versions of Mac Catalyst.

Additional context

Adding a version to the maccatalyst attribute text fixes the warning.

So there's no warning with this:

private void Tapped()
{
	if (OperatingSystem.IsIOSVersionAtLeast(15,0))
		DoSomething ();
}

[SupportedOSPlatform ("ios14.0")]
[SupportedOSPlatform ("maccatalyst14.0")]
public void DoSomething () {}