Skip to content

Commit 10e639e

Browse files
committed
Sema: Only diagnose unavailable attr when it is active for the target.
An attribute may be "active" but also not the most specific attribute for the current target and therefore ignored. Resolves rdar://107678512
1 parent 44be113 commit 10e639e

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,6 +1906,16 @@ void AttributeChecker::visitAvailableAttr(AvailableAttr *attr) {
19061906
!attr->isPackageDescriptionVersionSpecific())
19071907
return;
19081908

1909+
// Make sure there isn't a more specific attribute we should be using instead.
1910+
// findMostSpecificActivePlatform() is O(N), so only do this if we're checking
1911+
// an iOS attribute while building for macCatalyst.
1912+
if (attr->Platform == PlatformKind::iOS &&
1913+
isPlatformActive(PlatformKind::macCatalyst, Ctx.LangOpts)) {
1914+
if (attr != D->getAttrs().findMostSpecificActivePlatform(Ctx)) {
1915+
return;
1916+
}
1917+
}
1918+
19091919
SourceLoc attrLoc = attr->getLocation();
19101920
auto versionAvailability = attr->getVersionAvailability(Ctx);
19111921
if (versionAvailability == AvailableVersionComparison::Obsoleted ||
@@ -1932,16 +1942,6 @@ void AttributeChecker::visitAvailableAttr(AvailableAttr *attr) {
19321942
if (!attr->hasPlatform() || !attr->Introduced.has_value())
19331943
return;
19341944

1935-
// Make sure there isn't a more specific attribute we should be using instead.
1936-
// findMostSpecificActivePlatform() is O(N), so only do this if we're checking
1937-
// an iOS attribute while building for macCatalyst.
1938-
if (attr->Platform == PlatformKind::iOS &&
1939-
isPlatformActive(PlatformKind::macCatalyst, Ctx.LangOpts)) {
1940-
if (attr != D->getAttrs().findMostSpecificActivePlatform(Ctx)) {
1941-
return;
1942-
}
1943-
}
1944-
19451945
// Find the innermost enclosing declaration with an availability
19461946
// range annotation and ensure that this attribute's available version range
19471947
// is fully contained within that declaration's range. If there is no such
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %target-typecheck-verify-swift -target %target-cpu-apple-ios13.1-macabi -parse-as-library -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import
2+
3+
// REQUIRES: OS=macosx
4+
5+
struct BadStruct {
6+
@available(macCatalyst 13.1, *)
7+
@available(iOS, unavailable) // This attribute is inactive so we don't expect a diagnostic
8+
var availableOnCatalyst: Int
9+
10+
@available(macCatalyst, unavailable) // expected-error {{stored properties cannot be marked unavailable with '@available'}}
11+
@available(iOS 13, *)
12+
var unavailableOnCatalyst: Int
13+
}

0 commit comments

Comments
 (0)