Skip to content

Conversation

@buyaa-n
Copy link

@buyaa-n buyaa-n commented Dec 16, 2022

Two bugs found while investigating #6158 that fixed with this PR

  1. When a child API narrows down parent support version the guarding version was compared with parent version only when it should be compared with child version
[SupportedOSPlatform("ios")]
[SupportedOSPlatform("tvos")]
[SupportedOSPlatform("maccatalyst")]
class Program
{
    [SupportedOSPlatform("tvos10.2")]
    [SupportedOSPlatform("ios10.3")]
    [SupportedOSPlatform("maccatalyst10.3")]
    public static int P1 => 1;
}

class Test
{
    [SupportedOSPlatform("ios10.0")]
    public void M1()
    {
        var rate = (OperatingSystem.IsIOSVersionAtLeast(10, 3) || OperatingSystem.IsMacCatalystVersionAtLeast(10, 3) || OperatingSystem.IsTvOSVersionAtLeast(10, 3))
		    ? Program.P1 // was warning here even if it was guarded
                    : 0; 
    }
}
  1. When a called API has SupportedOSPlatform and ObsoletedOSPlatform attributes both and if the callsite attribute suppresses the Supported version the analyzer should warn only for the Obsoleted version. It was still warning for the Supported attribute even if it was empty / suppressed.
class Program
{
    [ObsoletedOSPlatform("ios7.0", "Use 'NSString.GetBoundingRect (CGSize, NSStringDrawingOptions, UIStringAttributes, NSStringDrawingContext)' instead.")]
    [ObsoletedOSPlatform("maccatalyst7.0", "Use 'NSString.GetBoundingRect (CGSize, NSStringDrawingOptions, UIStringAttributes, NSStringDrawingContext)' instead.")] // maccatalyst covered by ios, this attribute redundant
    [SupportedOSPlatform("ios")]
    [SupportedOSPlatform("maccatalyst")] // maccatalyst covered by ios, this attribute redundant
    public static void M3() { }
    
    [SupportedOSPlatform("ios")]
    public static void M1()
    {
         M3(); // it was reporting 2 diagnostics here, CA1416 and CA1422 when only CA1422 was expected
    }
}

Fixes #6158

@codecov
Copy link

codecov bot commented Dec 16, 2022

Codecov Report

Merging #6361 (544db0c) into main (1eb2caf) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #6361    +/-   ##
========================================
  Coverage   96.08%   96.08%            
========================================
  Files        1367     1360     -7     
  Lines      315352   315583   +231     
  Branches    10187    10189     +2     
========================================
+ Hits       302991   303234   +243     
+ Misses       9930     9916    -14     
- Partials     2431     2433     +2     

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.

.NET MAUI seeing lots of new CA1416 warnings

2 participants