Skip to content

[5.9] Sema: Only diagnose unavailable attr when it is active for the target #64962

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

Merged
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
20 changes: 10 additions & 10 deletions lib/Sema/TypeCheckAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1906,6 +1906,16 @@ void AttributeChecker::visitAvailableAttr(AvailableAttr *attr) {
!attr->isPackageDescriptionVersionSpecific())
return;

// Make sure there isn't a more specific attribute we should be using instead.
// findMostSpecificActivePlatform() is O(N), so only do this if we're checking
// an iOS attribute while building for macCatalyst.
if (attr->Platform == PlatformKind::iOS &&
isPlatformActive(PlatformKind::macCatalyst, Ctx.LangOpts)) {
if (attr != D->getAttrs().findMostSpecificActivePlatform(Ctx)) {
return;
}
}

SourceLoc attrLoc = attr->getLocation();
auto versionAvailability = attr->getVersionAvailability(Ctx);
if (versionAvailability == AvailableVersionComparison::Obsoleted ||
Expand All @@ -1932,16 +1942,6 @@ void AttributeChecker::visitAvailableAttr(AvailableAttr *attr) {
if (!attr->hasPlatform() || !attr->Introduced.has_value())
return;

// Make sure there isn't a more specific attribute we should be using instead.
// findMostSpecificActivePlatform() is O(N), so only do this if we're checking
// an iOS attribute while building for macCatalyst.
if (attr->Platform == PlatformKind::iOS &&
isPlatformActive(PlatformKind::macCatalyst, Ctx.LangOpts)) {
if (attr != D->getAttrs().findMostSpecificActivePlatform(Ctx)) {
return;
}
}

// Find the innermost enclosing declaration with an availability
// range annotation and ensure that this attribute's available version range
// is fully contained within that declaration's range. If there is no such
Expand Down
13 changes: 13 additions & 0 deletions test/Sema/availability_stored_unavailable_maccatalyst.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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

// REQUIRES: OS=macosx

struct BadStruct {
@available(macCatalyst 13.1, *)
@available(iOS, unavailable) // This attribute is inactive so we don't expect a diagnostic
var availableOnCatalyst: Int

@available(macCatalyst, unavailable) // expected-error {{stored properties cannot be marked unavailable with '@available'}}
@available(iOS 13, *)
var unavailableOnCatalyst: Int
}