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

Fix False positives found in Platform Compatibility Analyzer #5963

Merged
merged 4 commits into from
Apr 12, 2022

Conversation

buyaa-n
Copy link
Member

@buyaa-n buyaa-n commented Apr 11, 2022

Fix false positives found in platform relations edge case scenarios found in PCA (CA1416)

Fixes #5962

These false positives are mainly unhandled edge case scenarios of the new rule of iOS is MacCatalyst . Below scenarios are not reproduceable for platforms not having a relation, i.e not happening for platforms other than iOS/MacCatalyst.

Case 1: False positive when callsite and called API attributes are related and callsite has higher version support than the called API version for PlatformNeutralAssembly

[assembly: SupportedOSPlatform("MacCatalyst13.1")]
public class Test
{
    private static int field = 0;
    [SupportedOSPlatform("ios11.0")]
    public static void iOS11Method() { field = 1; } // Warns for the access to field
}

Case 2: False positive when API with [SupportedOSPlatformGuard("ios11.0")] attribute calls a field within a targeted assembly

[assembly: SupportedOSPlatform("ios10.0")]
class Test
{
    static readonly bool s_isiOS11OrNewer => OperatingSystem.IsIOSVersionAtLEast(11);

    [SupportedOSPlatformGuard("ios11.0")]
    private bool IsIos11Supported() => s_isiOS11OrNewer; // warns, not expected
    void M1()
    {
        if (IsIos11Supported())
        {
            SupportedOniOS11();
        }
    }
    [SupportedOSPlatform("ios11.0")]
    void SupportedOniOS11() { }
}

Case 3: False positive when API with iOS guard attribute is used within MacCatalyst targeted build with lower version

[assembly: SupportedOSPlatform("MacCatalyst13.1")]
public class Test
{
    [SupportedOSPlatformGuard("ios14.0")]
    internal static bool IsiOS14OrNewer => true;

    [SupportedOSPlatform("ios13.4")]
    public static void iOS13Method() { }

    static void M1()
    {
        iOS13Method(); // Warns, expected
        if (IsiOS14OrNewer)
            iOS13Method(); // Should not warn; This call site is reachable on: 'ios' 14.0 and later, 'MacCatalyst' 13.1 and later. 'Test.iOS13Method()' is only supported on: 'MacCatalyst' 13.4 and later.
            
    }
}

Needed for fixing dotnet/maui#823

@buyaa-n buyaa-n requested a review from a team as a code owner April 11, 2022 19:06
@codecov
Copy link

codecov bot commented Apr 11, 2022

Codecov Report

Merging #5963 (d4c7d11) into main (8ada8ef) will increase coverage by 0.00%.
The diff coverage is 97.04%.

❗ Current head d4c7d11 differs from pull request most recent head 99a0a95. Consider uploading reports for the commit 99a0a95 to get more accurate results

@@           Coverage Diff            @@
##             main    #5963    +/-   ##
========================================
  Coverage   96.04%   96.05%            
========================================
  Files        1315     1315            
  Lines      304760   304981   +221     
  Branches     9660     9667     +7     
========================================
+ Hits       292718   292939   +221     
+ Misses       9724     9723     -1     
- Partials     2318     2319     +1     

@buyaa-n buyaa-n enabled auto-merge (squash) April 12, 2022 00:16
@buyaa-n buyaa-n merged commit e898a9d into dotnet:main Apr 12, 2022
@github-actions github-actions bot added this to the vNext milestone Apr 12, 2022
@buyaa-n buyaa-n deleted the fix_case_1 branch April 12, 2022 00:56
@jmarolf jmarolf modified the milestones: vNext, .NET 7.x Nov 15, 2022
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

Successfully merging this pull request may close these issues.

False positives found in Platform Compatibility Analyzer
3 participants