Merge pull request #77333 from tshortli/defer-availability

Sema: TypeRefinementContextBuilder must not skip defer blocks
This commit is contained in:
Allan Shortlidge
2024-11-01 03:15:44 -07:00
committed by GitHub
3 changed files with 32 additions and 5 deletions

View File

@@ -550,10 +550,6 @@ private:
}
bool shouldSkipDecl(Decl *D) const {
// Implicit decls don't have source locations so they cannot have a TRC.
if (D->isImplicit())
return true;
// Only visit a node that has a corresponding concrete syntax node if we are
// already walking that concrete syntax node.
auto *concreteDecl = concreteSyntaxDeclForAvailableAttribute(D);
@@ -568,6 +564,12 @@ private:
PreWalkAction walkToDeclPre(Decl *D) override {
PrettyStackTraceDecl trace(stackTraceAction(), D);
// Implicit decls don't have source locations so they cannot have a TRC.
// However, some implicit nodes contain non-implicit nodes (e.g. defer
// blocks) so continue rather than skipping the node entirely.
if (D->isImplicit())
return Action::Continue();
if (shouldSkipDecl(D))
return Action::SkipNode();

View File

@@ -208,6 +208,16 @@ func functionWithWhile() {
}
}
// CHECK-NEXT: {{^}} (decl version=51 decl=functionWithDefer()
// CHECK-NEXT: {{^}} (condition_following_availability version=52
// CHECK-NEXT: {{^}} (if_then version=52
@available(OSX 51, *)
func functionWithDefer() {
defer {
if #available(OSX 52, *) {}
}
}
// CHECK-NEXT: {{^}} (decl_implicit version=50 decl=extension.SomeClass
// CHECK-NEXT: {{^}} (decl version=51 decl=extension.SomeClass
// CHECK-NEXT: {{^}} (decl_implicit version=51 decl=someStaticPropertyWithClosureInit

View File

@@ -28,7 +28,22 @@ let ignored3: Int = globalFuncAvailableOn52() // expected-error {{'globalFuncAva
// Functions without annotations should reflect the minimum deployment target.
func functionWithoutAvailability() {
// expected-note@-1 2{{add @available attribute to enclosing global function}}
// expected-note@-1 5{{add @available attribute to enclosing global function}}
defer {
let _: Int = globalFuncAvailableOn10_9()
let _: Int = globalFuncAvailableOn51() // expected-error {{'globalFuncAvailableOn51()' is only available in macOS 51 or newer}}
// expected-note@-1 {{add 'if #available' version check}}
let _: Int = globalFuncAvailableOn52() // expected-error {{'globalFuncAvailableOn52()' is only available in macOS 52 or newer}}
// expected-note@-1 {{add 'if #available' version check}}
if #available(OSX 51, *) {
let _: Int = globalFuncAvailableOn10_9()
let _: Int = globalFuncAvailableOn51()
let _: Int = globalFuncAvailableOn52() // expected-error {{'globalFuncAvailableOn52()' is only available in macOS 52 or newer}}
// expected-note@-1 {{add 'if #available' version check}}
}
}
let _: Int = globalFuncAvailableOn10_9()