Skip to content

Commit 08dab02

Browse files
authored
Merge pull request #62500 from tshortli/fix-cannot-be-more-available-than-enclosing-scope-diag
Sema: Don't diagnose explicitly unavailable decls as "more available than unavailable scope"
2 parents 9a22bac + f796dc9 commit 08dab02

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,11 +1903,14 @@ void AttributeChecker::visitAvailableAttr(AvailableAttr *attr) {
19031903

19041904
if (EnclosingDecl) {
19051905
if (EnclosingDeclIsUnavailable) {
1906-
diagnose(D->isImplicit() ? EnclosingDecl->getLoc() : attr->getLocation(),
1907-
diag::availability_decl_more_than_unavailable_enclosing,
1908-
D->getDescriptiveKind());
1909-
diagnose(EnclosingDecl->getLoc(),
1910-
diag::availability_decl_more_than_unavailable_enclosing_here);
1906+
if (!AttrRange.isKnownUnreachable()) {
1907+
diagnose(D->isImplicit() ? EnclosingDecl->getLoc()
1908+
: attr->getLocation(),
1909+
diag::availability_decl_more_than_unavailable_enclosing,
1910+
D->getDescriptiveKind());
1911+
diagnose(EnclosingDecl->getLoc(),
1912+
diag::availability_decl_more_than_unavailable_enclosing_here);
1913+
}
19111914
} else if (!AttrRange.isContainedIn(EnclosingAnnotatedRange.value())) {
19121915
diagnose(D->isImplicit() ? EnclosingDecl->getLoc() : attr->getLocation(),
19131916
diag::availability_decl_more_than_enclosing,

test/Sema/availability_versions.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,12 @@ class ClassAvailableOn10_51 { // expected-note {{enclosing scope requires availa
625625
@available(OSX, introduced: 10.9) // expected-error {{instance method cannot be more available than enclosing scope}}
626626
func someMethodAvailableOn10_9() { }
627627

628+
@available(OSX, unavailable)
629+
func someMethodUnavailable() { }
630+
631+
@available(*, unavailable)
632+
func someMethodUniversallyUnavailable() { }
633+
628634
@available(OSX, introduced: 10.52)
629635
var propWithGetter: Int { // expected-note{{enclosing scope requires availability of macOS 10.52 or newer}}
630636
@available(OSX, introduced: 10.51) // expected-error {{getter cannot be more available than enclosing scope}}

test/attr/attr_availability_transitive_osx.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,16 @@ extension Outer {
129129
func osx_more_available_but_still_unavailable_call_osx() {
130130
osx() // OK
131131
}
132+
133+
@available(OSX, unavailable)
134+
func osx_double_unavailable_call_osx() {
135+
osx() // OK
136+
}
137+
138+
@available(*, unavailable)
139+
func osx_universally_unavailable_call_osx() {
140+
osx() // OK
141+
}
132142

133143
// rdar://92551870
134144
func osx_call_osx_more_available_but_still_unavailable() {

0 commit comments

Comments
 (0)