diff --git a/lib/Sema/TypeCheckAttr.cpp b/lib/Sema/TypeCheckAttr.cpp index ec81f0b5327ae..93df148d0df2f 100644 --- a/lib/Sema/TypeCheckAttr.cpp +++ b/lib/Sema/TypeCheckAttr.cpp @@ -1964,7 +1964,9 @@ void AttributeChecker::visitAvailableAttr(AvailableAttr *attr) { if (!AttrRange.isContainedIn(*EnclosingAnnotatedRange)) { // Members of extensions of nominal types with available ranges were // not diagnosed previously, so only emit a warning in that case. - auto limit = (enclosingDecl != parent && isa(parent)) + bool inExtension = isa( + D->getDeclContext()->getTopmostDeclarationDeclContext()); + auto limit = (enclosingDecl != parent && inExtension) ? DiagnosticBehavior::Warning : DiagnosticBehavior::Unspecified; diagnose(D->isImplicit() ? enclosingDecl->getLoc() diff --git a/test/attr/attr_availability_osx.swift b/test/attr/attr_availability_osx.swift index c80e90a626f9d..9e0da7419b0d2 100644 --- a/test/attr/attr_availability_osx.swift +++ b/test/attr/attr_availability_osx.swift @@ -81,7 +81,7 @@ func doSomethingDeprecatedOniOS() { } doSomethingDeprecatedOniOS() // okay @available(macOS 10.10, *) -struct TestStruct {} // expected-note {{enclosing scope requires availability of macOS 10.10 or newer}} +struct TestStruct {} // expected-note 2 {{enclosing scope requires availability of macOS 10.10 or newer}} @available(macOS 10.10, *) 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 extension TestStruct { @available(macOS 10.9, *) // expected-warning {{instance method cannot be more available than enclosing scope}} func doFifthThing() {} + + struct NestedStruct { + @available(macOS 10.9, *) // expected-warning {{instance method cannot be more available than enclosing scope}} + func doSixthThing() {} + } } @available(macOS 10.11, *)