Skip to content

Commit de2f1a9

Browse files
authored
Merge pull request #65013 from tshortli/modify-accessor-cannot-be-more-available-5.9
[5.9] Sema: Downgrade over availability diagnostics to warnings for implicit decls
2 parents feb5aa6 + 2600120 commit de2f1a9

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,7 +1896,8 @@ void AttributeChecker::visitAvailableAttr(AvailableAttr *attr) {
18961896
}
18971897

18981898
// Skip the remaining diagnostics in swiftinterfaces.
1899-
auto *SF = D->getDeclContext()->getParentSourceFile();
1899+
auto *DC = D->getDeclContext();
1900+
auto *SF = DC->getParentSourceFile();
19001901
if (SF && SF->Kind == SourceFileKind::Interface)
19011902
return;
19021903

@@ -1926,7 +1927,7 @@ void AttributeChecker::visitAvailableAttr(AvailableAttr *attr) {
19261927
return;
19271928
}
19281929

1929-
if (auto *PD = dyn_cast<ProtocolDecl>(D->getDeclContext())) {
1930+
if (auto *PD = dyn_cast<ProtocolDecl>(DC)) {
19301931
if (auto *VD = dyn_cast<ValueDecl>(D)) {
19311932
if (VD->isProtocolRequirement() && !PD->isObjC()) {
19321933
diagnoseAndRemoveAttr(attr,
@@ -1958,13 +1959,17 @@ void AttributeChecker::visitAvailableAttr(AvailableAttr *attr) {
19581959
EnclosingAnnotatedRange.emplace(
19591960
AvailabilityInference::availableRange(enclosingAttr, Ctx));
19601961
if (!AttrRange.isContainedIn(*EnclosingAnnotatedRange)) {
1961-
// Members of extensions of nominal types with available ranges were
1962-
// not diagnosed previously, so only emit a warning in that case.
1963-
bool inExtension = isa<ExtensionDecl>(
1964-
D->getDeclContext()->getTopmostDeclarationDeclContext());
1965-
auto limit = (enclosingDecl != parent && inExtension)
1966-
? DiagnosticBehavior::Warning
1967-
: DiagnosticBehavior::Unspecified;
1962+
auto limit = DiagnosticBehavior::Unspecified;
1963+
if (D->isImplicit()) {
1964+
// Incorrect availability for an implicit declaration is likely a
1965+
// compiler bug so make the diagnostic a warning.
1966+
limit = DiagnosticBehavior::Warning;
1967+
} else if (enclosingDecl != parent) {
1968+
// Members of extensions of nominal types with available ranges were
1969+
// not diagnosed previously, so only emit a warning in that case.
1970+
if (isa<ExtensionDecl>(DC->getTopmostDeclarationDeclContext()))
1971+
limit = DiagnosticBehavior::Warning;
1972+
}
19681973
diagnose(D->isImplicit() ? enclosingDecl->getLoc()
19691974
: attr->getLocation(),
19701975
diag::availability_decl_more_than_enclosing,
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -I %t -I %S/Inputs/custom-modules -parse-stdlib -parse-as-library -typecheck -verify -target x86_64-apple-ios15.4-macabi %s
1+
// RUN: %target-swift-frontend -I %t -I %S/Inputs/custom-modules -parse-stdlib -parse-as-library -typecheck -verify -target %target-cpu-apple-ios15.4-macabi %s
22

33
// REQUIRES: objc_interop
44
// REQUIRES: maccatalyst_support
@@ -7,7 +7,17 @@ import Available_NSObject
77

88
@available(iOS 15.0, *)
99
open class OverAvailableClass: NSBaseClass {}
10-
// expected-error@-1 {{initializer cannot be more available than enclosing scope}}
10+
// expected-warning@-1 {{initializer cannot be more available than enclosing scope}}
1111
// expected-note@-2 {{initializer implicitly declared here with availability of Mac Catalyst 13.1 or newer}}
1212
// expected-note@-3 {{enclosing scope requires availability of Mac Catalyst 15.0 or newer}}
1313

14+
extension NSBaseClass {
15+
@available(iOS 15.0, *)
16+
// expected-warning@+3 {{_modify accessor cannot be more available than enclosing scope}}
17+
// expected-note@+2 {{_modify accessor implicitly declared here with availability of Mac Catalyst 13.1 or newer}}
18+
// expected-note@+1 {{enclosing scope requires availability of Mac Catalyst 15.0 or newer}}
19+
var property: Int {
20+
get { 1 }
21+
set {}
22+
}
23+
}

0 commit comments

Comments
 (0)