Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1902,11 +1902,13 @@ static void MergePlatformAttributes(ImmutableArray<AttributeData> immediateAttri
if (childAttributes.TryGetValue(platform, out var childAttribute))
{
// only later versions could narrow, other versions ignored
if (childAttribute.SupportedFirst.IsGreaterThanOrEqualTo(attributes.SupportedFirst) &&
(attributes.SupportedSecond == null || attributes.SupportedSecond < childAttribute.SupportedFirst))
if (childAttribute.SupportedFirst.IsGreaterThanOrEqualTo(attributes.SupportedFirst))
{
attributes.SupportedSecond = childAttribute.SupportedFirst;
supportFound = true;
if (attributes.SupportedSecond == null || attributes.SupportedSecond < childAttribute.SupportedFirst)
{
attributes.SupportedSecond = childAttribute.SupportedFirst;
}
}

if (childAttribute.UnsupportedFirst != null)
Expand Down Expand Up @@ -2011,7 +2013,7 @@ static void CheckAttributesConsistency(SmallDictionary<string, Versions> childAt
{
allowList = true;
}
else if (DenyList(attributes))
else if (DenyList(attributes) || !attributes.IsSet())
{
unsupportedList.Add(platform);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4158,6 +4158,104 @@ static void UnsupportsIos() { }
await VerifyAnalyzerCSAsync(source, s_msBuildPlatforms);
}

[Fact, WorkItem(50337, "https://github.com/dotnet/sdk/issues/50337")]
public async Task SuppressedMacCatalystWithinChildAttributesShouldAlsoAppliedToParentAttributesOnMerge()
{
var source = @"
using System;
using System.Runtime.Versioning;

[SupportedOSPlatform (""maccatalyst"")]
[SupportedOSPlatform (""ios"")]
partial class TestType {
[UnsupportedOSPlatform (""maccatalyst"")]
[SupportedOSPlatform (""ios"")]
void DoSomething ()
{
Console.WriteLine (GetSomething);
}

[UnsupportedOSPlatform (""maccatalyst"")]
[SupportedOSPlatform (""ios"")]
public static object GetSomething {
[UnsupportedOSPlatform (""maccatalyst"")]
[SupportedOSPlatform (""ios"")]
get => """";
}
}";
await VerifyAnalyzerCSAsync(source, s_msBuildPlatforms);
}

[Fact]
public async Task SuppressedMacCatalystWithinChildAttributesShouldAlsoAppliedToParentAttributesOnMergeRegression()
{
var source = @"
using System;
using System.Runtime.Versioning;

[assembly: SupportedOSPlatform (""maccatalyst"")]
[assembly: SupportedOSPlatform (""ios"")]
[assembly: SupportedOSPlatform (""macos"")]
[assembly: SupportedOSPlatform (""tvos"")]

[SupportedOSPlatform (""maccatalyst"")]
[SupportedOSPlatform (""ios"")]
[SupportedOSPlatform (""macos"")]
[SupportedOSPlatform (""tvos"")]
partial class TestType {

[UnsupportedOSPlatform (""maccatalyst"")]
[SupportedOSPlatform (""ios"")]
[SupportedOSPlatform (""macos"")]
[SupportedOSPlatform (""tvos"")]
public static IntPtr FromContext (INativeObject context)
{
return context.GetHandle ();
}
}

public static class NativeObjectExtensions {
static public IntPtr GetHandle (this INativeObject self)
{
return IntPtr.Zero;
}
}

public interface INativeObject {}
";
await VerifyAnalyzerCSAsync(source, s_msBuildPlatforms);
}

[Fact]
public async Task ChildMethodNarrowedPlatformSupportCalledShouldWarn()
{
var source = @"
using System;
using System.Runtime.Versioning;

[assembly: SupportedOSPlatform (""macos"")]
[assembly: SupportedOSPlatform (""tvos"")]

[SupportedOSPlatform (""macos"")]
[SupportedOSPlatform (""tvos"")]
partial class TestType {

public static IntPtr FromContext ()
{
return [|GetHandle()|];
}

[SupportedOSPlatform (""macos"")]
[UnsupportedOSPlatform (""tvos"")]
static public IntPtr GetHandle ()
{
return IntPtr.Zero;
}
}
";
await VerifyAnalyzerCSAsync(source, s_msBuildPlatforms);
}

private string GetFormattedString(string resource, params string[] args) =>
string.Format(CultureInfo.InvariantCulture, resource, args);

Expand Down
Loading