Skip to content

Commit 8a16cdc

Browse files
authored
Merge pull request #64297 from tshortli/downgrade-over-availability-anywhere-in-extensions
2 parents 78dbbba + 328fdc8 commit 8a16cdc

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1964,7 +1964,9 @@ void AttributeChecker::visitAvailableAttr(AvailableAttr *attr) {
19641964
if (!AttrRange.isContainedIn(*EnclosingAnnotatedRange)) {
19651965
// Members of extensions of nominal types with available ranges were
19661966
// not diagnosed previously, so only emit a warning in that case.
1967-
auto limit = (enclosingDecl != parent && isa<ExtensionDecl>(parent))
1967+
bool inExtension = isa<ExtensionDecl>(
1968+
D->getDeclContext()->getTopmostDeclarationDeclContext());
1969+
auto limit = (enclosingDecl != parent && inExtension)
19681970
? DiagnosticBehavior::Warning
19691971
: DiagnosticBehavior::Unspecified;
19701972
diagnose(D->isImplicit() ? enclosingDecl->getLoc()

test/attr/attr_availability_osx.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func doSomethingDeprecatedOniOS() { }
8181
doSomethingDeprecatedOniOS() // okay
8282

8383
@available(macOS 10.10, *)
84-
struct TestStruct {} // expected-note {{enclosing scope requires availability of macOS 10.10 or newer}}
84+
struct TestStruct {} // expected-note 2 {{enclosing scope requires availability of macOS 10.10 or newer}}
8585

8686
@available(macOS 10.10, *)
8787
extension TestStruct { // expected-note {{enclosing scope requires availability of macOS 10.10 or newer}}
@@ -107,6 +107,11 @@ extension TestStruct { // expected-note {{enclosing scope requires availability
107107
extension TestStruct {
108108
@available(macOS 10.9, *) // expected-warning {{instance method cannot be more available than enclosing scope}}
109109
func doFifthThing() {}
110+
111+
struct NestedStruct {
112+
@available(macOS 10.9, *) // expected-warning {{instance method cannot be more available than enclosing scope}}
113+
func doSixthThing() {}
114+
}
110115
}
111116

112117
@available(macOS 10.11, *)

0 commit comments

Comments
 (0)