Skip to content

Commit 882e105

Browse files
authored
Merge pull request swiftlang#63361 from tshortli/suppress-over-availability-diags-for-synthesized-code
AST: Correct inferred availability attributes on synthesized declarations
2 parents aad6680 + aa5194c commit 882e105

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

lib/AST/Decl.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -398,14 +398,8 @@ void Decl::forEachAttachedMacro(MacroRole role,
398398
}
399399

400400
const Decl *Decl::getInnermostDeclWithAvailability() const {
401-
const Decl *enclosingDecl = this;
402-
// Find the innermost enclosing declaration with an @available annotation.
403-
while (enclosingDecl != nullptr) {
404-
if (enclosingDecl->getAttrs().hasAttribute<AvailableAttr>())
405-
return enclosingDecl;
406-
407-
enclosingDecl = enclosingDecl->getDeclContext()->getAsDecl();
408-
}
401+
if (auto attrAndDecl = getSemanticAvailableRangeAttr())
402+
return attrAndDecl.value().second;
409403

410404
return nullptr;
411405
}

test/Concurrency/concurrency_availability.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: %target-swift-frontend -parse-stdlib -target x86_64-apple-macosx10.14 -typecheck -verify %s
22
// RUN: %target-swift-frontend -parse-stdlib -target x86_64-apple-macosx11 -typecheck %s
3+
// RUN: %target-swift-frontend -parse-stdlib -target x86_64-apple-macosx12 -typecheck %s -DTARGET_MACOS_12
34
// REQUIRES: OS=macosx
45

56
func f() async { } // expected-error{{concurrency is only available in}}
@@ -19,3 +20,12 @@ struct S {
1920
actor A {
2021
}
2122
}
23+
24+
// The synthesized unownedExecutor inside this extension on S should inherit
25+
// availability from S to avoid availability errors.
26+
#if TARGET_MACOS_12
27+
extension S {
28+
actor A2 {
29+
}
30+
}
31+
#endif

0 commit comments

Comments
 (0)